ACP
ACP

Reputation: 35268

convert ds.Tables[1].Rows[0].ToString() to int

I can't convert ds.Tables[1].Rows[0].ToString() to an int.

ds.Tables[1].Rows[0] = 100; 

Gives an error can't convert.

Upvotes: 0

Views: 19087

Answers (3)

David
David

Reputation: 5456

ds.Tables[1].Rows[0] returns a DataRow. You need to indicate the column that you want to assign the value:

ds.Tables[1].Rows[0]["Your column name"] = value;

Upvotes: 3

Kenneth J
Kenneth J

Reputation: 4896

Are you missing the column? ds.Tables[1].Rows[0][column] = value;

Upvotes: 1

Jack Marchetti
Jack Marchetti

Reputation: 15754

string test = Convert.Int32(ds.Tables[0].Rows[0]["YourIntegerColumn"].ToString())

If your column isnt an integer, then it's not gonna work, so you'll probly want to check if the column is null, then check if its parsable to an int using Int.TryParse

Upvotes: 3

Related Questions