I have got this code that might return no results found - null
String result
string searchUby = "SELECT text FROM rooms WHERE year=@year AND event=@eventAND text=@text AND z is NULL";
SqlCommand sqlcom = new SqlCommand(searchUby, conn);
sqlcom.Parameters.AddWithValue("@event",event.Text);
sqlcom.Parameters.AddWithValue("@text", cb_room.SelectedItem);
sqlcom.Parameters.AddWithValue("@year",klientClass.Year());
conn.Open();
result = sqlcom.ExecuteScalar().ToString(); // on this line ex occurs
conn.Close();
I get this exception:
NullReferenceException: Object reference not set to an instance of an object.
May someone help me with solving this?