Reputation: 3
I have this C# code.
j = myAccountDataset.Tables["AccountsTables"].Rows.Count;
for (i = 0; i <= (j - 1); i++ )
{
listAccountList.Items.Add(myAccountDataset.Tables[0].Rows[i][1]);
}
this.listAccountList.SelectedIndex = 0;
the idea is to iterate inside the dataset and add the items to the list. but i am getting the following errors: Error 1 The best overloaded method match for 'System.Web.UI.WebControls.ListItemCollection.Add(string)' has some invalid arguments
Argument1: cannot convert from 'object' to 'string'
i must be doing something wrong. thye error is in the line: listAccountList.Items.Add(myAccountDataset.Tables[0].Rows[i][1]);
thank you.
Upvotes: 0
Views: 2728
Reputation: 4937
A little more description
Your myAccountDataset.Tables[0].Rows[i][1] is a typeless object, the Add method is expecting a string, you will need to cast the object to a string. The simplest method of doing this is to add the .ToString() operator to your datarow object
myAccountDataset.Tables[0].Rows[i][1].Tostring()
Upvotes: 0