Am building window form application for a clinic using VS2010.
On the form in have a searchbutton that display data baseon the RegistrationNo.
When i test the application, provide the Registration number and click the search
button nothing is display, and no error message is display too.
Here is my code
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
`
You have a typo
RegistraionNo instead of RegistrationNo
in
another in
You’ll copy 100 lines of