我的连接字符串:string con="Server=localhost;database=Test;uid=sa;pwd=sa12345";
comboBox要绑定的是:"select stuName from StudentInfo where score<60"的数据。
textBox要绑定的是:"select info from StudentInfo where score<60"的数据。
C#中如何为comboBox和textBox绑定SQL数据库指定字段名(求具体代码!)
答案:3 悬赏:0
解决时间 2021-03-11 21:06
- 提问者网友:神仙爷爷
- 2021-03-11 17:22
最佳答案
- 二级知识专家网友:如果这是命
- 2021-03-11 18:50
comboBox:
string con = "Server=localhost;database=Test;uid=sa;pwd=sa12345";
SqlConnection conn = new SqlConnection(con);
conn.Open();
string sql = "select stuName from StudentInfo where score<60";
SqlDataAdapter sda = new SqlDataAdapter(sql, conn);
DataTable dt = new DataTable();
sda.Fill(dt);
conn.Close();
comboBox1.DataSource = dt;
textBox:
string con = "Server=localhost;database=Test;uid=sa;pwd=sa12345";
SqlConnection conn = new SqlConnection(con);
conn.Open();
string sql = "select info from StudentInfo where score<60";
SqlDataAdapter sda = new SqlDataAdapter(sql, conn);
DataTable dt = new DataTable();
sda.Fill(dt);
conn.Close();
textBox1.Text = dt.Rows[0][0].ToString();
string con = "Server=localhost;database=Test;uid=sa;pwd=sa12345";
SqlConnection conn = new SqlConnection(con);
conn.Open();
string sql = "select stuName from StudentInfo where score<60";
SqlDataAdapter sda = new SqlDataAdapter(sql, conn);
DataTable dt = new DataTable();
sda.Fill(dt);
conn.Close();
comboBox1.DataSource = dt;
textBox:
string con = "Server=localhost;database=Test;uid=sa;pwd=sa12345";
SqlConnection conn = new SqlConnection(con);
conn.Open();
string sql = "select info from StudentInfo where score<60";
SqlDataAdapter sda = new SqlDataAdapter(sql, conn);
DataTable dt = new DataTable();
sda.Fill(dt);
conn.Close();
textBox1.Text = dt.Rows[0][0].ToString();
全部回答
- 1楼网友:承载所有颓废
- 2021-03-11 20:57
SQL语句的条件变了一下
- 2楼网友:怪咖小青年
- 2021-03-11 20:22
你好!
用vs中工具箱的数据中的BindingSource控件来绑定,去百度查一下如何使用这个控件
打字不易,采纳哦!
我要举报
如以上问答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯