I'm trying to write a general function for running SQL commands that only bring back one result.
I'm getting the following error:
Exception Details: System.InvalidOperationException: ExecuteScalar: Connection property has not been initialized.
Source Error:
Line 130:
Line 131: SQLCommand.CommandText = SQL;
Line 132: String myResult = (String)SQLCommand.ExecuteScalar();
Line 133:
Line 134: return myResult;
Source File: c:\Development\pros\Functions.cs Line: 132
The code is:
public static string SingleSQL(string SQL)
{
SqlConnection SQLCON = new SqlConnection(ConfigurationManager.ConnectionStrings["PIDDBConnectionString"].ToString());
SQLCON.Open();
SqlCommand SQLCommand = new SqlCommand();
SQLCommand.CommandType = CommandType.Text;
SQLCommand.CommandText = SQL;
String myResult = (String)SQLCommand.ExecuteScalar();
return myResult;
}