C# Winform读数据库并显示在对应文本框中
C# Winform读数据库并显示在对应文本框中
数据库表中的字段。分别是,名字和编号
Name No
张三 11
李四 12
王五 13
现在把这个表中所有的都读取出来,然后怎么样把对应的数据放到我指定的textBox中呢??
string sql = "Select * From Biao";
SqlCommand cmd = new SqlCommand(sql, Conn.rs);
Conn.rs.Open();
SqlDataReader dr = cmd.ExecuteReader();
dr.Read();
textBox1.Text = dr["Name"].ToString();//放入李四
textBox2.Text = dr["Name"].ToString();//放入张三
textBox3.Text = dr["Name"].ToString();//放入王五
textBox4.Text = dr["No"].ToString();//放入12
textBox5.Text = dr["No"].ToString();//放入11
textBox6.Text = dr["No"].ToString();//放入13
dr.Close();
比如:
textBox1(李四) textBox4(12)
textBox2(张三) textBox5(11)
textBox3(王五) textBox6(13)
要读出表中的所有条数,数据。
怎么写才能把指定的数据放到指定的各个textBox文本框中呢?
请各位写个详细代码,谢谢!