Asp.net 从数据集中添加列表框项

Asp.net 从数据集中添加列表框项,asp.net,listbox,dataset,loops,for-loop,Asp.net,Listbox,Dataset,Loops,For Loop,我有这个密码 j=myAccountDataset.Tables[“AccountsTables”].Rows.Count; 对于(i=0;i,ListItemCollection的Add方法只接受两种类型—字符串或ListItem 请参阅MSDN文档。您需要传递字符串而不是对象: listAccountList.Items.Add(myAccountDataset.Tables[0].Rows[i][1].ToString()); 再多描述一下 myAccountDataset.Tables

我有这个密码

j=myAccountDataset.Tables[“AccountsTables”].Rows.Count;

对于(i=0;i,ListItemCollection的Add方法只接受两种类型—字符串或ListItem 请参阅MSDN文档。您需要传递字符串而不是对象:

listAccountList.Items.Add(myAccountDataset.Tables[0].Rows[i][1].ToString());

再多描述一下

myAccountDataset.Tables[0].Rows[i][1]是一个无类型对象,Add方法需要字符串,您需要将对象强制转换为字符串。最简单的方法是将.ToString()运算符添加到datarow对象

myAccountDataset.Tables[0].Rows[i][1].Tostring()
myAccountDataset.Tables[0].Rows[i][1].Tostring()