C#(让数据值显示到文本框,显示出来了,但是显示的不是我要的那个字段)哪位大大帮忙参考改下
SqlConnectioncon=newSqlConnection("Server=.;DataBase=rencai;uid=sa;pwd=123");SqlComma...
SqlConnection con = new SqlConnection("Server=.;DataBase=rencai;uid=sa;pwd=123");
SqlCommand cmd = new SqlCommand("select * from jianli", con);
con.Open();
SqlDataReader dr = cmd.ExecuteReader();
//a.QueryByUsername(name);
while (dr.Read())
{
this.TextBox1.Text = dr[1].ToString();
this.TextBox2.Text = dr[2].ToString();
this.TextBox3.Text = dr[6].ToString();
this.TextBox4.Text = dr[7].ToString();
this.TextBox6.Text = dr[10].ToString();
this.TextBox7.Text = dr[5].ToString();
this.TextBox8.Text = dr[8].ToString();
}
dr.Close();
con.Close();
非常感谢光临此问题的各位大大 展开
SqlCommand cmd = new SqlCommand("select * from jianli", con);
con.Open();
SqlDataReader dr = cmd.ExecuteReader();
//a.QueryByUsername(name);
while (dr.Read())
{
this.TextBox1.Text = dr[1].ToString();
this.TextBox2.Text = dr[2].ToString();
this.TextBox3.Text = dr[6].ToString();
this.TextBox4.Text = dr[7].ToString();
this.TextBox6.Text = dr[10].ToString();
this.TextBox7.Text = dr[5].ToString();
this.TextBox8.Text = dr[8].ToString();
}
dr.Close();
con.Close();
非常感谢光临此问题的各位大大 展开
若以下回答无法解决问题,邀请你更新回答
1个回答
展开全部
while (dr.Read())
{
if(dr[某字段].ToString()=="某条件")//满足条件再进行赋值
{
this.TextBox1.Text = dr[1].ToString();
this.TextBox2.Text = dr[2].ToString();
this.TextBox3.Text = dr[6].ToString();
this.TextBox4.Text = dr[7].ToString();
this.TextBox6.Text = dr[10].ToString();
this.TextBox7.Text = dr[5].ToString();
this.TextBox8.Text = dr[8].ToString();
}
}
{
if(dr[某字段].ToString()=="某条件")//满足条件再进行赋值
{
this.TextBox1.Text = dr[1].ToString();
this.TextBox2.Text = dr[2].ToString();
this.TextBox3.Text = dr[6].ToString();
this.TextBox4.Text = dr[7].ToString();
this.TextBox6.Text = dr[10].ToString();
this.TextBox7.Text = dr[5].ToString();
this.TextBox8.Text = dr[8].ToString();
}
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询