c# - sqlite database not returning results -


Why does not my query return results? I am using C # to give this column header but no row. Is there any problem in my selection statement?

Here is my code:

  conn = new SQLite connection ("data source = local.db; version = 3; new = false; compress = true"); Datatale data = new datatile (); SQLiteDataReader Reader; (SQLiteTransaction trans = conn.BeginTransaction ()) {{SQLiteCommand mycommand = new SQLiteCommand (conn)) using {mycommand.CommandText = "SELECT * TAGTABLE WHERE TAG = '" + Tag + "';"; Reader = mycommand.ExecuteReader (); } Trans.Commit (); Data.load (reader); Reader.Close (); Reader.Dispose (); Trans.Dispose (); } Return data;   

TAGTABLE has the following fields:

  TID int, tag varchar (500), file path varchar (1000)    

You do not need a transaction, try the following:

 < Code> DataTable Data = New DataTable (); (SQLiteCommand mycommand = new SQLiteCommand (conn)) using the SQLiteConnection conn = new SQLiteConnection ("Data source = local.db; version = 3; New = False; compress = true;")) {mycommand.CommandText = " SELECT * Coggables from where Tag = @Tig; "; Mycommand.Parameters.AddWithValue ("@ Tag", tag); Conn.Open (); (Using the SQLiteDataReader reader = mycommand.ExecuteReader ()) {data.Load (reader); }} Return data; The most likely reason is that it will not return anything if  SELECT  does not produce any results.  

Also note that anything can be used with the using statement to implement the IDisposable interface, so the objects can be used There is no need to close / settle down.

Note that SQL has changed to use parametric queries, this will help to reduce the possibility of SQL injection attacks, and it is generally cleaner.

Comments

Popular posts from this blog

mysql - BLOB/TEXT column 'value' used in key specification without a key length -

ruby on rails - Convert a Activerecord result with has_one associations into a single hash per record -

javascript - Read complete data from stream from onMessage -