c# reading integer fields from database
- by arnoldino
what is wrong with this code?
try
{
if (cmd == null) getConnection();
cmd.CommandText = "Select id from HMonthInventary where machine_id=37";
SQLiteDataReader reader = cmd.ExecuteReader();
if (reader.HasRows==true)
{
reader.Read();
string s = reader[0].ToString(); // return first element
reader.Close();
return s;
}
reader.Close();
return null;
}
catch (Exception e)
{
MessageBox.Show("Caught exception: " + e.Message+"|"+cmd.CommandText);
return null;
}
I checked the sql statement, it turns the right value. why can't I read it?
the returnvalue is "".