Here is my code:
private void button1_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection("Data Source=MANINOTEBOOK\\SQLEXPRESS;Integrated Security=SSPI;Initial Catalog=Casesheet");
con.Open();
SqlCommand cmd = new SqlCommand("select PatientID from FTR where PatientID='" + textBox1.Text + "'", con);
textBox2.Text = cmd.ExecuteScalar().ToString();
if (textBox2.Text == textBox1.Text)
{
Consultation cs = new Consultation(textBox1.Text);
cs.Show();
}
else
{
MessageBox.Show("Data not found");
}
}
When i compile this code i get an error "NullReferenceException was unhandled". I dont know how to resolve it. I need to check the value generated in the "execute scalar" command is null or not. Kindly help me in resolving this problem.