正在使用 VS2010 为诊所构建窗口表单应用程序。在表单上有一个搜索按钮,显示基于 RegistrationNo 的数据。
当我测试应用程序时,提供注册号并单击搜索
按钮没有显示任何内容,也没有显示错误消息。
这是我的代码
string connectionstring = "Data Source=localhost;Initial Catalog=HMS;Persist Security Info=True;User ID=Developer;Password=abc@123";
SqlConnection connection = new SqlConnection(connectionstring);
string SelectStatement = "SELECT * FROM MyTable where RegistrationNo = '@RegistraionNo'";
SqlCommand insertcommand = new SqlCommand(SelectStatement, connection);
insertcommand.Parameters.AddWithValue("@RegistrationNo", txtsearch.Text);
SqlDataReader reader;
try
{
connection.Open();
reader = insertcommand.ExecuteReader();
while (reader.Read())
{
textBox3.Text = reader["RegistratioNo"].ToString();
textBox1.Text = reader["FirstName"].ToString();
textBox2.Text = reader["LastName"].ToString();
genderOption.Text = reader["Sex"].ToString();
textBox7.Text = reader["Contact"].ToString();
textBox4.Text = reader["Age"].ToString();
textBox5.Text = reader["Weight"].ToString();
textBox6.Text = reader["Weight"].ToString();
comboBox1.Text = reader["Tribe"].ToString();
}//end while
reader.Close();
}
catch (SqlException ex)
{
throw ex;
}//end catch
finally
{
connection.Close();
}// end finally
`