c# - ExecuteScalar: Object reference not set etc -


Friends, I need some help. This is my first time developing an app that has DB, please consider, please Forgive my mistakes

I am trying to get the boolean value from the database and if it is to apply another loop on it ... but it is throwing the "object reference not set" error on the ExecuteScalar function.

Here the code is: -

  string sql = "// here is my SQL query"; String connectionstring = "// here is my connection string ..."; SqlConnection connection = new SqlConnection (connectionstring); SQL Commands Command = New SQL Commands (SQL, Connection); order. Connection = connection; Connection.Open (); Bool ev = (bool) command. Exclute form (); If (ev == true) {MessageBox.Show ("some error"); } Other {// some code}   

What am I doing?

Support will really be appreciated.

Regards.

Probably query reverse tap. Try this:

  bool? Ev = (bool?) Command. Exclute form (); If (ev.GetValueOrDefault (wrong)) {MessageBox.Show (...); }   

? means empty, so it can be the value given by the query in this way as null .

Comments

Popular posts from this blog

c - Mpirun hangs when mpi send and recieve is put in a loop -

python - Apply coupon to a customer's subscription based on non-stripe related actions on the site -

java - Unable to get JDBC connection in Spring application to MySQL -