newbie on getting value from a dataset

  • Thread starter Thread starter Danny Ni
  • Start date Start date
D

Danny Ni

Hi,

I tried to get a value from dataset. Here is my code:
int intCustomerID = (int)(dsCustomer.Tables[0].Rows[0].ItemArray[0]);

I keep getting "Specified cast is not valid", I know for a fact that the
value is an integer.
So how do I cast it?

TIA
 
You can reference it with just the indexes:
DataTable dt = new DataTable();

DataColumn dc = new DataColumn("Whaever",
Type.GetType("System.Int32"));

dt.Columns.Add(dc);

DataRow dro = dt.NewRow();

dro[0] = 24;

dt.Rows.Add(dro);

int i = (int)dt.Rows[0][0];//24


--
W.G. Ryan MVP Windows - Embedded

Have an opinion on the effectiveness of Microsoft Embedded newsgroups?
Let Microsoft know!
https://www.windowsembeddedeval.com/community/newsgroups
 
Back
Top