Why am I not able to retrieve the value of ID (which does exist) using
ExecuteScalar() ? Do i simply have to use ExecuteReader() instead?
My problem snippet:
string mySQL = "SELECT ID FROM Table WHERE TableID = 1";
//TableID is a unique ID within Table, no dupiclates-risk
myCommand = new SqlCommand(mySQ L, myConn);
myConn.Open();
int myID = (int)myCommand. ExecuteScalar() ;
myConn.Close();
return myID;
My result:
Object reference not set to an instance of an object.
ExecuteScalar() ? Do i simply have to use ExecuteReader() instead?
My problem snippet:
string mySQL = "SELECT ID FROM Table WHERE TableID = 1";
//TableID is a unique ID within Table, no dupiclates-risk
myCommand = new SqlCommand(mySQ L, myConn);
myConn.Open();
int myID = (int)myCommand. ExecuteScalar() ;
myConn.Close();
return myID;
My result:
Object reference not set to an instance of an object.
Comment