I am having trouble calling my nonquery. When I run this I get the following error- “ExecuteNonQuery: CommandText property has not been initialized”
//delete from the database
OdbcCommand cmdCommand = new OdbcCommand(tSQL, Global.gADOConnection);
tSQL = "Delete from SEARCH_CRITERIA where CRITERIA_ID = " + iCriteriaID;
Global.gADOConnection.Open();
cmdCommand.ExecuteNonQuery();
Global.gADOConnection.Close();
I am not sure why I continue to get this error. Can anyone help me please?
Thanks.
You’re setting the value of
tSQLafter you’ve passed it into theOdbcCommandconstructor. I suspect that’s not what you wanted. Try:However:
usingstatement to dispose the command at the endI’d also strongly advise you not to use a global variable for the database connection. Create a new connection each time you need a database operation, and dispose of it at the end:
Let the connection pool handle making that efficient in terms of the underlying network connections.