I have Oledbconnection like this(this is sample code):
public string var1, var2;
...
OleDbConnection Connection;
Connection = new OleDbConnection("Provider=Microsoft.Jet.OleDb.4.0;Data Source=" +
Server.MapPath("~/db.mdb"));
OleDbCommand Command1, Command2;
Command1 = new OleDbCommand("SELECT DT FROM Table1 WHERE ID = 1", Connection);
Command2 = new OleDbCommand("SELECT GT FROM Table1 WHERE ID = 1", Connection);
Connection.Open();
var1= (string)Command1.ExecuteScalar();
var2= (string)Command2.ExecuteScalar();
Connection.Close();
When Oledbcommand getting null, ExecuteScalar getting error.
I can use try-catch or I can control if object is null or not. But is it possible easy way to do it? I just want if query getting null, I want to set null var1 and var2.
Thank you.