c# and query result
-
What is the result of a query in c# when is false or is true for example i have the following query and i want to do something when is false. How i manage this? string rfyear = ((string)cmd_year.ExecuteScalar()); i want to manage with "if" if i can to do something like this... if (rfyear.Length == 0) { MessageBox.Show("the query is false "); } else{ MessageBox.Show("OK"); textBox1.Text = rfyear;
-
What is the result of a query in c# when is false or is true for example i have the following query and i want to do something when is false. How i manage this? string rfyear = ((string)cmd_year.ExecuteScalar()); i want to manage with "if" if i can to do something like this... if (rfyear.Length == 0) { MessageBox.Show("the query is false "); } else{ MessageBox.Show("OK"); textBox1.Text = rfyear;
It all depends on what your query is actually returning: it is very possible that your line:
string rfyear = ((string)cmd_year.ExecuteScalar());
Will not work, but throw an InvalidCastException because the data coming back can't be cast to a string - it may work if you change it to:
string rfyear = cmd_year.ExecuteScalar().ToString();
But...I wouldn't recommend it as there is a very good chance that you will get a string containing the name of the type of the value returned. What does your query return when it works and when it fails?
The universe is composed of electrons, neutrons, protons and......morons. (ThePhantomUpvoter)