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();
SQL语句的条件变了一下
用vs中工具箱的数据中的BindingSource控件来绑定,去百度查一下如何使用这个控件