[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 284
  • Last Modified:

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
0
Meinhoonaa
Asked:
Meinhoonaa
  • 5
  • 4
  • 3
  • +1
1 Solution
 
Guru JiCommented:
Try this

txtDNumber.Text = tbl.Rows[0].ItemArray["DealerLicenseNum"].value.ToString();
0
 
MeinhoonaaAuthor Commented:
there is no value property.
0
 
Guru JiCommented:
Sorry I was thinking something else

Try this

txtDNumber.Text = Convert.ToString(tbl.Rows[0].ItemArray["DealerLicenseNum"]);
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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
 
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
 
MeinhoonaaAuthor Commented:
thank you
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

  • 5
  • 4
  • 3
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now