Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
DataView/DataSet/DataReader
Message
From
09/01/2007 15:38:50
Alexandre Palma
Harms Software, Inc.
Alverca, Portugal
 
 
To
09/01/2007 15:28:22
General information
Forum:
ASP.NET
Category:
ADO.NET
Miscellaneous
Thread ID:
01183234
Message ID:
01183954
Views:
25
>>>So when I query my data source, what is returned is not the datatype that is in the source table, so I must "cast" it to what I want. Is that it?
>>
>>What you get is an object, which has no knowledge of what you wan to do with it, so you cast to the type you want.
>
>
>Ding! Ding! :)
>I thought I should get back the same datatype(s) that is in data source that I query.
>I see.
>Thanks for the clarification.

And you get sam if you field is for example a datetime and you then try to cast it to an integer you will get an error, what happens is that the dataset doesn't know what is the type at least at design type that's wh y you need to cast it. the other option is to use typed datasets in that case you will be accessing the data as any object e.g.
CustomerDataSet customers = new CustomerDataSet();
SqlDataAdapter adapter = new SqlDataAdapter(
  "SELECT * FROM dbo.Customers;",
  "Data Source=(local);Integrated " +
  "Security=SSPI;Initial Catalog=Northwind");

adapter.Fill(customers, "Customers");

foreach(CustomerDataSet.CustomersRow customerRow in customers.Customers)
  Console.WriteLine(customerRow.CustomerID);
Alexandre Palma
Senior Application Architect
Previous
Reply
Map
View

Click here to load this message in the networking platform