我正在尝试一个按钮,将MySql服务器中的表数据插入文本框。我正在学习一个教程,每个人都有相同的想法,但是在将信息插入文本框时遇到一个问题,我收到错误消息“无法将方法组“读取”转换为非延迟类型“布尔””
我不确定该怎么做。我正在Visual Studio 2019中使用c#和远程MySql服务器。
private void Button1_Click(object sender, EventArgs e)
{
bool temp = false;
MySqlConnection con = new MySqlConnection("server=xxx;user id=xxx;password=xxx;database=xxx");
con.Open();
MySqlCommand cmd = new MySqlCommand("select * from CadCall where id='" + txtID.Text.Trim() + "'", con);
MySqlDataReader dr = cmd.ExecuteReader();
while (dr.Read))
{
txtDate.Text = dr.GetString(1);
txtTime.Text = dr.GetString(2);
txtCall.Text = dr.GetString(3);
txtAddress.Text = dr.GetString(4);
txtApt.Text = dr.GetString(5);
txtPhone.Text = dr.GetString(6);
txtInfo.Text = dr.GetString(7);
txtCaller.Text = dr.GetString(8);
txtCallerPhone.Text = dr.GetString(9);
txtNote.Text = dr.GetString(10);
txtOfficer.Text = dr.GetString(11);
txtDis.Text = dr.GetString(12);
txtArr.Text = dr.GetString(13);
txtFin.Text = dr.GetString(14);
txtFd.Text = dr.GetString(15);
txtFl.Text = dr.GetString(16);
txtDisp.Text = dr.GetString(17);
txtCase.Text = dr.GetString(18);
temp = true;
}
if (temp == false)
MessageBox.Show("No Active Call Found");
con.Close();
因此,最后,当此人按下按钮时,它将在表格中搜索ID(即1),然后用信息填充其余文本框。
感谢进阶!
答案 0 :(得分:0)
while (dr.Read()) //it's a method.
{
txtDate.Text = dr.GetString(1);
..
}
请参阅示例- https://dev.mysql.com/doc/dev/connector-net/6.10/html/T_MySql_Data_MySqlClient_MySqlDataReader.htm
答案 1 :(得分:0)
您应该写
while (dr.Read())
装有
while (dr.Read))