Click here to Skip to main content
14,543,273 members
Rate this:
Please Sign up or sign in to vote.
See more:
//below is my code
string ID = dset.Tables[0].Rows["ID"].ToString();

//where "ID" IS A COLUMN in registration table data type is int
Posted
Updated 10-Feb-13 20:23pm
v2
Comments
Orcun Iyigun 11-Feb-13 2:23am
   
What is the problem?
ntitish 11-Feb-13 2:31am
   
sir here i am retrieving data from table where ID data type is in int...
it is showing error like this

The best overloaded method match for 'System.Data.DataRowCollection.this[int]' has some invalid arguments
Argument '1': cannot convert from 'string' to 'int'
Rate this:
Please Sign up or sign in to vote.

Solution 1

Hi,

In your code there is one problem
string ID = dset.Tables[0].Rows["ID"].ToString();

here you haven't mentioned row no., you have only mentioned column name ie. ID
rewrite ur code as below
string ID = dset.Tables[0].Rows[n]["ID"].ToString();

where 'n'= index of row starting from 0.
   
v2
Comments
[no name] 11-Feb-13 4:20am
   
Good one man. +5
[no name] 11-Feb-13 5:36am
   
thnx :)
ntitish 11-Feb-13 7:33am
   
thanks sir....i not seen i for got to give row value thanks once again...
Rate this:
Please Sign up or sign in to vote.

Solution 3

I'd use TryParse[^] to make sure the string is really an integer before going ahead with the conversion.
   
Rate this:
Please Sign up or sign in to vote.

Solution 2

int id = Convert.ToInt16(ID.ToString());

try this...
   
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100