need help with data table

I am getting error converting from vb to c#

VB
 txtDNumber.Text = tbl.Rows(0).Item("DealerLicenseNum").ToString

c#
txtDNumber.Text = tbl.Rows[0].ItemArray["DealerLicenseNum"].ToString();
error: cannot implicit convert type string to int
MeinhoonaaAsked:
Who is Participating?
 
YZlatCommented:
how come? Well, these are two different programming languages. This is the syntax and that's that.

use either one:

txtDNumber.Text = tbl.Rows[0].ItemArray[tbl.Columns.IndexOf("DealerLicenseNum")].ToString();

or
txtDNumber.Text = tbl.Rows[0]["DealerLicenseNum"].ToString();
0
 
Guru JiCommented:
Try this

txtDNumber.Text = tbl.Rows[0].ItemArray["DealerLicenseNum"].value.ToString();
0
 
MeinhoonaaAuthor Commented:
there is no value property.
0
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
Guru JiCommented:
Sorry I was thinking something else

Try this

txtDNumber.Text = Convert.ToString(tbl.Rows[0].ItemArray["DealerLicenseNum"]);
0
 
MeinhoonaaAuthor Commented:
Error
Cannot implicitly convert string to int
0
 
Guru JiCommented:
are you looping through the ItemArray ? Can you post your loop code
0
 
MeinhoonaaAuthor Commented:
no looping, just getting row[0]
0
 
LIONKINGCommented:
Have you tried replacing the "DealerLicenseNum" with the column index?
Something like (assuming DealerLicenseNum is the first column):

tbl.Rows[0].ItemArray[0].ToString();
0
 
YZlatCommented:
you can't use column name, you have to use column index instead
0
 
MeinhoonaaAuthor Commented:
then how come vb.net allows it?
0
 
YZlatCommented:
you can use

txtDNumber.Text = tbl.Rows[0].ItemArray[tbl.Columns.IndexOf("DealerLicenseNum")].ToString();
0
 
YZlatCommented:
or

txtDNumber.Text = tbl.Rows[0]["DealerLicenseNum"].ToString();
0
 
MeinhoonaaAuthor Commented:
thank you
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.