机器人|listBox1如何绑定数据 C#中winform

机器人|listBox1如何绑定数据 C#中winform


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);
【机器人|listBox1如何绑定数据 C#中winform】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();