Getting data into array.

Posts   
 
    
rai
User
Posts: 41
Joined: 25-Jan-2007
# Posted on: 27-Jul-2007 06:51:55   

Please can anyone help me out in this.

I want to retrieve data from database and put into array. It is a date field so i had done something like this to get the total number of rows: int TotalRow = (int)adapter.GetScalar(PublishDatesFields.PubDate, null, AggregateFunction.CountRow, null); Declared array : DateTime[] NonPublishDates = new DateTime[TotalRow];

now i dont know how can i retrieve data from database and put into array.

please anyone can help me out...in this.

Thanks in advance..........................

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 27-Jul-2007 09:37:44   

Please pots the SQL query you want to execute.

Why don't you use a dynamicList (DataTable)?

rai
User
Posts: 41
Joined: 25-Jan-2007
# Posted on: 27-Jul-2007 10:14:24   

Walaa wrote:

Please pots the SQL query you want to execute.

Why don't you use a dynamicList (DataTable)?

I got a table PubDate

id Date Description

1 24/04/2007 Public function 2 27/07/2007 zzzzzzz 3 23/06/2006 wwwww 4 12/02/2006 tuhguig

I got an interface where user will enter the date. I want to put this dates into array so that when the user enter the a date then it will be compared with this dates. If it will match one of this dates that ....then error.

I am using adapter........but since iam very new to this..coz this is my first development so iam bit confused..what is the best option do solve this.

Sugesstions please!!!!

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 27-Jul-2007 10:24:51   

The best option is to select the date field using a dynamicList. (check the manual's section: "Using the generated code -> Adapter/SelfServicing -> Using TypedViews, TypedLists and dynamic lists -> Using Dynamic Lists")

A dynamicList is a dataTable, so you can use it directly, or you can extract values from it into an array.

rai
User
Posts: 41
Joined: 25-Jan-2007
# Posted on: 27-Jul-2007 12:58:54   

Walaa wrote:

The best option is to select the date field using a dynamicList. (check the manual's section: "Using the generated code -> Adapter/SelfServicing -> Using TypedViews, TypedLists and dynamic lists -> Using Dynamic Lists")

A dynamicList is a dataTable, so you can use it directly, or you can extract values from it into an array.

My query is: select Date from Pubs From Pubdate where DatePart('yyyy',Date) = "2007"

I had done something like this: static public DataTable GetPubDates() { DataAccessAdapter adapter = new DataAccessAdapter(dbConnectionString()); ResultsetFields fields = new ResultsetFields(1); fields.DefineField(PubDatesFieldIndex.Date, 0, "PubDate", "PubDate"); DataTable results = new DataTable(); adapter.FetchTypedList(fields, results, null, false); return results;

    }

// no idea how to how to do the where clause

Client side i had done something like this: DataTable dt = PublishDates.GetPubDates(); lblTest.Text = (dt.Rows[1].IsNull("PubDate")).ToString();

but iam getting the result as false.

any suggestion please........................

thanks in advance

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 27-Jul-2007 15:43:18   

// no idea how to how to do the where clause

Try the following:

EntityField field = PubDatesFields.Date;
field.SetExpression(new DbFunctionCall( "YEAR", new object[] { PubDatesFields.Date} );
);
PredicateExpression filter = new PredicateExpression(field == "2007");

Client side i had done something like this: DataTable dt = PublishDates.GetPubDates(); lblTest.Text = (dt.Rows[1].IsNull("PubDate")).ToString();

but iam getting the result as false.

Which result? would you please elaborate on the last part. What are you trying to do with the following line? lblTest.Text = (dt.Rows[1].IsNull("PubDate")).ToString();