c# 如何将满足条件的数据库中的内容现实到textbox中
string str1 = this.dataGridView1.CurrentRow.Cells[0].Value.ToString();this.namebox.Text = str1;
MessageBox.Show(this.namebox.Text);
string str="select * from Worker where WorkerName='"+branchnamelab.Text+"'";
SqlCommand sqlcomm=new SqlCommand(str,da.link());
string LoginName=string.Empty;
string LoginEmail=string.Empty;
SqlDataReader reader = sqlcomm.ExecuteReader();
if (reader.Read())
{
LoginName = reader.GetValue(2).ToString();
LoginEmail = reader.GetValue(5).ToString();
}
loginbox.Text=LoginName;
Emailbox.Text=LoginEmail;
以上代码的意思是:鼠标点击DataGridView中某一行时(此DataGridView中只有一个字段),其内容显示到branchnamelab.Text中,然后根据branchnamelab.Text中的内容将其他信息添加到textbox中。但是当读取数据表Worker时,reader.GetValue(2).ToString()中内容怎么为空啊?也就是说LoginName 为空。怎么回事啊?感觉SQL语句没错啊。 --------------------编程问答-------------------- LoginName = reader.GetValue(2).ToString();
这么写看可以获取值不
LoginName = reader[2].ToString();
--------------------编程问答-------------------- 楼主结贴率…… --------------------编程问答-------------------- 呵呵,我已经知道错在哪了。
补充:.NET技术 , C#