SQLite数据查询

using Mono.Data.Sqlite

using System.Data

               /// <summary> 
                 /// 执行一个查询语句,返回一个包含查询结果的DataTable 
                 /// </summary> 
                 /// <param name="sql">要执行的查询语句</param> 
                 /// <param name="parameters">执行SQL查询语句所需要的参数,参数必须以它们在SQL语句中的顺序为准</param> 
                 /// <returns></returns> 
                 public DataTable ExecuteDataTable(string sql, SQLiteParameter[] parameters) 
                 { 
                         using (SqliteConnection connection = new SqliteConnection(connectionString)) 
                         { 
                                 using (SqliteCommand command = new SqliteCommand(sql, connection)) 
                                 { 
                                         if (parameters != null) 
                                         { 
                                                 command.Parameters.AddRange(parameters); 
                                         } 
                                         SqliteDataAdapter adapter = new SqliteDataAdapter(command); 
                                         DataTable data = new DataTable(); 
                                         adapter.Fill(data); 
                                         return data; 
                                 } 
                         } 
        
                 }

posted on 2016-09-12 16:29  Roger634  阅读(595)  评论(0编辑  收藏  举报

导航