让梦想从这里开始

因为有了梦想,我们才能拥有奋斗的目标,而这些目标凝结成希望的萌芽,在汗水与泪水浇灌下,绽放成功之花。

listBox1如何绑定数据 C#中winform

using (SqlConnection conn = new SqlConnection(connStr)) { try { conn.Open; MessageBox.Show("数据连接成功"); string Sql = "select [id], [name] from [sysobjects] where [type] = 'u' order by [name]"; SqlCommand cmd = new SqlCommand(Sql, conn); Sql...


using (SqlConnection conn = new SqlConnection(connStr))

{

try

{

conn.Open;

MessageBox.Show("数据连接成功");

string Sql = "select [id], [name] from [sysobjects] where [type] = 'u' order by [name]";

SqlCommand cmd = new SqlCommand(Sql, conn);

SqlDataAdapter sda = new SqlDataAdapter;

DataSet ds = new DataSet;

sda.SelectCommand = cmd;

sda.Fill(ds,"shujubiao");

listBox1.DataSource = ds.Tables[0];

listBox1.DisplayMember = "name";

listBox1.ValueMember = "id";

}

catch (SqlException ex)

{

MessageBox.Show("数据库连接失败,请检查连接字符串是否正确," + ex.ToString);

}

finally

{

conn.Close;



相关资讯