我想以数据库组合的形式从数据库中获取文本框中列的所有数据。 这是我的代码。
CON.Open();
SqlCommand CMD = new SqlCommand("SELECT CUST_NAME FROM CUSTOMER WHERE CUST_ID=CUST_NAME", CON);
SqlDataReader DR = CMD.ExecuteReader();
while (DR.Read())
{
CUST_NAME.Text = DR["CUST_NAME"].ToString();
}
CON.Close();
所以请帮帮我
答案 0 :(得分:1)
你应该让你的文本框多行并重新调整大小
CUST_NAME.Multiline = true;
然后将代码更改为
CON.Open();
SqlCommand CMD = new SqlCommand("SELECT CUST_NAME FROM CUSTOMER WHERE CUST_ID=CUST_NAME", CON);
SqlDataReader DR = CMD.ExecuteReader();
while (DR.Read())
{
CUST_NAME.Text = DR["CUST_NAME"].ToString() + "\r\n";
}
CON.Close();
答案 1 :(得分:1)
需要一点点改变。
CON.Open();
SqlCommand CMD = new SqlCommand("SELECT CUST_NAME FROM CUSTOMER WHERE CUST_ID=CUST_NAME", CON);
SqlDataReader DR = CMD.ExecuteReader();
while (DR.Read())
{
CUST_NAME.Text += DR["CUST_NAME"].ToString() + "\r\n";
}
CON.Close();
由于
答案 2 :(得分:0)
从DataReader
绑定到组合框看起来像这样:
CON.Open();
SqlCommand CMD = new SqlCommand("SELECT CUST_NAME FROM CUSTOMER WHERE CUST_ID=CUST_NAME", CON);
SqlDataReader DR = CMD.ExecuteReader();
DataTable dt = new DataTable();
dt.Load(DR);
comboBox1.DataSource = dt;
comboBox1.DisplayMember = "CUST_NAME";
comboBox1.ValueMember = "CUST_ID";
CON.Close();