string connStr = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
private void button4_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection();
con.Open();
str = "select * from Department where Code='" + codeTextBox.Text.Trim() + "'";
com = new SqlCommand(str, con);
SqlDataReader reader = com.ExecuteReader();
if (reader.Read())
{
dep_NameTextBox.Text = reader["Name"].ToString();
dep_TypeTextBox.Text = reader["Dep_Type"].ToString();
//TextBox4.Text = reader["ADDRESS"].ToString();
//TextBox5.Text = reader["PHNO"].ToString();
//TextBox6.Text = reader["STATE"].ToString();
reader.Close();
con.Close();
}
An unhandled exception of type 'System.NullReferenceException' occurred in voucher.exe
Additional information: Object reference not set to an instance of an object.
how to resolve it?
or how to retrieve related id data in text boxes in other query ?