I use this function to make query:
public SQLiteDataReader returnDataReader(string txtQuery)
{
SQLiteCommand cmd = new SQLiteCommand();
try
{
cmd.Connection = Openconn();
cmd.CommandText = txtQuery;
SQLiteDataReader rd;
rd = cmd.ExecuteReader();
return rd;
}
catch (Exception Ex)
{
throw Ex;
}
finally
{
cmd = null;
}
}
And this is my query:
SQLiteDataReader data = db.returnDataReader("SELECT created_at FROM Transactions ORDER BY created_at DESC LIMIT 1");
I tried to get value of created_at
field from query like as:
string res = data["created_at"].ToString();
It returns me error. Also I have checked this query directly in Sqlite manager. It works and return one row.
Error is:
System.InvalidOperationException occurred HResult=0x80131509
Message=No current row Source=System.Data.SQLite StackTrace: at System.Data.SQLite.SQLiteDataReader.CheckValidRow() at System.Data.SQLite.SQLiteDataReader.GetValue(Int32 i) at System.Data.SQLite.SQLiteDataReader.get_Item(String name) at Ukraine.StatisticService.lastsync() in D:\Projects\c-tests-ukraine\Ukraine\Library\StatisticService.cs:line 25 at Ukraine.Main.Form1_Load(Object sender, EventArgs e) in D:\Projects\c-tests-ukraine\Ukraine\Main.cs:line 81 at System.Windows.Forms.Form.OnLoad(EventArgs e) at System.Windows.Forms.Form.OnCreateControl() at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
at System.Windows.Forms.Control.CreateControl() at System.Windows.Forms.Control.WmShowWindow(Message& m) at System.Windows.Forms.Control.WndProc(Message& m) at System.Windows.Forms.ScrollableControl.WndProc(Message& m) at System.Windows.Forms.Form.WmShowWindow(Message& m) at System.Windows.Forms.Form.WndProc(Message& m) at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m) at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m) at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)