Datarow convert to int and string

Jelmer

Regular
Joined
Jan 11, 2006
Messages
96
Why doesn't this work ?:

C#:
                   foreach (DataRow dr in dataTable.Rows)
                    {
                        //Nieuwe class vullen
                        cust[cust.Length + 1] = new Class_customers(Int32.Parse(dr[0].ToString), dr[1].ToString, dr[2], dr[3],

I'll get te following error:

With Int32.Parse(dr[0].ToString):

Methode for Int32.pars has some invalid arguments
dr[0].ToString : Argument cannot convert from 'method group' to 'string'

Whats wrong ? :(
 
Last edited by a moderator:
All the .ToString statements should be .ToString() - notice the () at the end.

Also if you know the field is of a particular type it is easier / faster to cast it correctly rather than convert ot a string and then parse it.

i.e.
C#:
cust[cust.Length + 1] = new Class_customers((int) dr[0], dr[1].ToString, dr[2], dr[3],...
 
Back
Top