我目前正在开发注册系统,我想要的功能是当我从ComboBox
选择一个学号时,它会显示姓名,年级,年龄等信息。TextBox/es
。
这是我现在的代码:
class MySQL
{
internal static string host = "localhost";
internal MySqlConnection con = new MySqlConnection("host=" + host + ";user=root;database=dbenrollmentsystem");
internal MySqlCommand cmd = new MySqlCommand();
internal MySqlDataReader dr;
internal MySqlDataAdapter da = new MySqlDataAdapter();
public void Connect()
{
Disconnect();
con.Open();
}
public void Disconnect()
{
if (con.State == System.Data.ConnectionState.Open)
{
con.Close();
}
}
}
我有这个:
r.Connect();
r.da = new MySqlDataAdapter("SELECT * FROM tblgeneral WHERE LRN LIKE @search OR LRN LIKE @search", r.con);
r.cmd = r.da.SelectCommand;
r.cmd.Parameters.AddWithValue("search", "%" + cbItems.Text + "%");'
txtFirstName.Text ="" + r.dr.GetString("FirstName");
r.cmd.ExecuteNonQuery();
r.Disconnect();
但这引发了一个例外:
"数据阅读器中没有当前查询"
你能在我的代码中指出什么错误吗?