我引用的是System.Data.SQLite.dll
我希望这个操作类里有
像 public int ExecuteSQL(string strSQL)
public DataTable GetDataTable(string strSQL)
之类的函数,这样操作起来比较方便.
我希望这个操作类里有
像 public int ExecuteSQL(string strSQL)
public DataTable GetDataTable(string strSQL)
之类的函数,这样操作起来比较方便.
解决方案 »
- 弱弱的问下.安装 net framework 2.0 sp2 之前要不要先装 net framework 2.0?
- 点击右边的按钮就能下拉列表框,点击按钮后弹出一个类似的列表框容器
- 怎么把c++做的一个工程集成到c#中去??
- 关于linq问题,string[].Contains(string param)---有没有办法忽略大小写?
- DateTimePicker如何去掉选择是的日!!!在线等!(急)
- C#如何将日本的日期转化为“XX-YY-ZZ”的格式,有这样的类吗,求教类库达人
- help!关于串口程序
- NET Remoting 问题(急盼回应)
- 初学c#同事说不能在外部service上实现树,不知道大家是怎么实现的。
- WinForm下面这样的线框是怎么实现的?
- 在windows mobile 下,当输入法状态改变,改变Form的高度以达到滚动的目的
- 谁用c#做过png8转png4位啊。。。我转完之后有些颜色总是不对,100分
我这个貌似要比你的好用一点1using System;
2using System.Collections.Generic;
3using System.Text;
4using System.Data.SQLite;
5using System.Data;
6using System.Configuration;
7using System.Web;
8using System.Collections;
9namespace FTchina
10...{
11 public class shujuku
12 ...{
13
14 protected static SQLiteConnection conn = new SQLiteConnection();
15 protected static SQLiteCommand comm = new SQLiteCommand();
16 protected static string connstr = System.Configuration.ConfigurationManager.AppSettings["ConnectionString"];
17
18 /**//// <summary>
19 /// 打开数据库连接
20 /// </summary>
21 public static void OpenConnection()
22 ...{
23 CheckConnection();
24 }
25 public static bool CheckConnection()
26 ...{
27 if (conn.State == ConnectionState.Closed)
28 ...{
29 try
30 ...{
31 conn.ConnectionString = connstr;
32 comm.Connection = conn;
33 conn.Open();
34 }
35 catch
36 ...{
37
38
39 return false;
40 }
41 }
42 return true;
43 }
44 /**//// <summary>
45 /// 关闭当前数据库连接
46 /// </summary>
47 public static void CloseConnection()
48 ...{
49 if (conn.State == ConnectionState.Open)
50 ...{
51 conn.Close();
52 conn.Dispose();
53 comm.Dispose();
54 }
55 }
56 /**//// <summary>
57 /// 执行Sql查询语句
58 /// </summary>
59 /// <param name="sqlstr">传入的Sql语句</param>
60 public static bool ExecuteSql(string sqlstr)
61 ...{
62 try
63 ...{
64 OpenConnection();
65 comm.CommandType = CommandType.Text;
66 comm.CommandText = sqlstr;
67 comm.ExecuteNonQuery();
68 Copyright.CommonContext.Current.QueryExecutions++;
69
70 return true;
71 }
72 catch (System.Exception er)
73 ...{
74
75 return false;
76 }
77 finally
78 ...{
79 CloseConnection();
80 }
81 }
82
83 /**//// <summary>
84 /// 在事务中处理大量数据
85 /// </summary>
86 /// <param name="sqls"></param>
87 public static void ExecuteSqlTransaction(ArrayList sqls)
88 ...{
89
90 OpenConnection();
91
92 SQLiteTransaction transaction = conn.BeginTransaction();
93 try
94 ...{
95
96 for (int i = 0; i < sqls.Count; i++)
97 ...{
98 comm.CommandType = CommandType.Text;
99 comm.CommandText = sqls[i].ToString();
100
101 comm.ExecuteNonQuery();
102
103 Copyright.CommonContext.Current.QueryExecutions++;
104
105 }
106 transaction.Commit();
107 }
108 catch (System.Exception er)
109 ...{
110
111 transaction.Rollback();
112 }
113 finally
114 ...{
115 CloseConnection();
116 }
117 }
118 /**//// <summary>
119 /// 返回指定Sql语句的DataTable
120 /// </summary>
121 /// <param name="sqlstr">传入的Sql语句</param>
122 /// <returns>DataTable</returns>
123 public static DataTable GetDataTable(string sqlstr)
124 ...{
125 return GetDataSet(sqlstr).Tables[0];
126
127 }
128
129
130 /**//// <summary>
131 /// 获取只包含架构信息的表
132 /// </summary>
133 /// <param name="sqlstr"></param>
134 /// <returns></returns>
135 public static DataTable GetSchemaTable(string sqlstr)
136 ...{
137 DataTable dt = new DataTable();
138 try
139 ...{
140 OpenConnection();
141 comm.CommandType = CommandType.Text;
142 comm.CommandText = sqlstr;
143
144 SQLiteDataReader dr = comm.ExecuteReader(CommandBehavior.SchemaOnly);
145 dt = dr.GetSchemaTable();
146 dr.Close();
147 }
148 catch (System.Exception er)
149 ...{
150
151 }
152 finally ...{ CloseConnection(); }
153 return dt;
154 }
155
156 /**//// <summary>
157 /// 返回指定Sql语句的DataSet
158 /// </summary>
159 /// <param name="sqlstr">传入的Sql语句</param>
160 /// <returns>DataTable</returns>
161 public static DataSet GetDataSet(string sqlstr)
162 ...{
163 SQLiteDataAdapter da = new SQLiteDataAdapter();
164 DataSet dataset = new DataSet();
165 try
166 ...{
167 OpenConnection();
168 comm.CommandType = CommandType.Text;
169 comm.CommandText = sqlstr;
170 da.SelectCommand = comm;
171 da.Fill(dataset);
172 Copyright.CommonContext.Current.QueryExecutions++;
173 }
174 catch (System.Exception er)
175 ...{
176
177 }
178 finally
179 ...{
180 CloseConnection();
181 }
182 return dataset;
183 }
184
185 //检测数据是否存在,返回真假
186 public static bool testread(string sqlstr)
187 ...{
188 return (GetDataSet(sqlstr).Tables[0].Rows.Count > 0);
189 }
190
191 /**//// <summary>
192 /// 返回特定值的查询结果
193 /// </summary>
194 /// <param name="wKey">列名称 如 "select com from table where id=3 "中的com</param>
195 /// <param name="fTable">表名称 如 "select com from table"中的table</param>
196 /// <param name="wStr">限制条件 如 "select com from table where id=3 "中的id=3</param>
197 /// <returns></returns>
198 public static string GetValueByKey(string wKey, string fTable, string wStr)
199 ...{
200 try
201 ...{
202 return GetDataTable("select " + wKey + " from " + fTable + " where " + wStr).Rows[0][0].ToString();
203 }
204 catch (System.Exception er)
205 ...{
206
207 return "";
208 }
209 }
210
211
212 分页的方法page为当前页码,NUMCount为每页数据#region 分页的方法page为当前页码,NUMCount为每页数据
213 public static DataSet ShowForPage(string table, string Where, int curragePage, int NUMCount)
214 ...{
215 int number = 0;
216 if (curragePage > 1)
217 ...{
218 number = NUMCount * (curragePage - 1);
219 }
220
221 string strsql = "select * from " + table + " where " + Where + " order by id desc limit " + number + "," + NUMCount;
222 return GetDataSet(strsql);
223 }
224 #endregion
225 }
226}刚找到的,还没测试.
SQLite操作类