listbox如何绑定数据
DataTable dt = myClass1.get_DataTable( "select top 1 * from _ItemInfo ");
ListBox1.Items.Clear();
for (int i = 0; i < dt.Columns.Count; i++)
{
ListItem item = new ListItem();
item.Value = dt.Columns[i].Caption;
item.Text = dt.Columns[i].Caption;
ListBox1.Items.Add(item);
----------------
搜索到这个,但
DataTable dt = myClass1.get_DataTable( "select top 1 * from _ItemInfo ");这句是怎么个用法 呀??
------解决方案--------------------public static DataTable get_DataTable(string sql)
{
//连接数据库语句
System.Data.SqlClient.SqlConnection cn = System.Data.SqlClient.SqlConnection( "server=.;uid=sa;pwd=sa;database=northwind; ");
System.Data.SqlClient.SqlDataAdapter da = System.Data.SqlClient.SqlDataAdapter(sql , cn);
DataSet ds = new DataSet();
da.Fill(ds);
return ds.Tables[0];
}