首页 > Python基础教程 >
-
C#教程之手把手教你使用C#操作SQLite数据库,新建(2)
您可以使用 AND 或 OR 运算符来结合 N 个数量的条件。在这里,XXXX 可以是任何数字或字符串值。
例
我们在球员中筛选出名字中包含James的球员
1 using System; 2 using System.Collections.Generic; 3 using System.Data.SQLite; 4 using System.Data; 5 using System.IO; 6 using System.Data.Common; 7 using System.Diagnostics; 8 9 10 namespace CSharp_SQLite 11 { 12 class Program 13 { 14 15 static void Main(string[] args) 16 { 17 string dbPath = "NBAStars.nba"; 18 Stopwatch timer = new Stopwatch(); 19 timer.Start(); 20 CSQLiteHelper sqlhelper = new CSQLiteHelper(dbPath); 21 sqlhelper.OpenDbConn(); 22 sqlhelper.BeginTransaction(); 23 sqlhelper.ExecuteNonQuery("delete from Stars"); 24 #region 球员信息 25 sqlhelper.ExecuteNonQuery("insert into Stars (Name,Team,Number) values('Michael Jordan','Bulls','23')"); 26 sqlhelper.ExecuteNonQuery("insert into Stars (Name,Team,Number) values('James Harden','Rockets','13')"); 27 sqlhelper.ExecuteNonQuery("insert into Stars (Name,Team,Number) values('Lebron James','Cavaliers','23')"); 28 sqlhelper.ExecuteNonQuery("insert into Stars (Name,Team,Number) values('Tracy Mcgrady','Rockets','1')"); 29 sqlhelper.ExecuteNonQuery("insert into Stars (Name,Team,Number) values('Yao Ming','Rockets','11')"); 30 sqlhelper.ExecuteNonQuery("insert into Stars (Name,Team,Number) values('Kevin Garnett','Timberwolves','21')"); 31 sqlhelper.ExecuteNonQuery("insert into Stars (Name,Team,Number) values('Tim Duncan','Supers','21')"); 32 sqlhelper.ExecuteNonQuery("insert into Stars (Name,Team,Number) values('Vince Carter','Nets','15')"); 33 sqlhelper.ExecuteNonQuery("insert into Stars (Name,Team,Number) values('Michael Carter Williams','76ers','10')"); 34 #endregion 35 sqlhelper.Commit(); 36 sqlhelper.CloseDbConn(); 37 timer.Stop(); 38 Console.WriteLine("初始化数据库表单用时:" + timer.Elapsed); 39 40 41 CSQLiteHelper sqlHelper = new CSQLiteHelper(dbPath); 42 sqlHelper.OpenDbConn(); 43 sqlHelper.BeginTransaction(); 44 DataTable dt = sqlHelper.Query("select Name, Number from Stars where Name like '%James%'").Tables[0]; 45 sqlHelper.Commit(); 46 sqlHelper.CloseDbConn(); 47 Console.WriteLine("名字中包含James的球员有:"); 48 for (int i = 0; i < dt.Rows.Count; i++) 49 { 50 Console.WriteLine(dt.Rows[i]["Name"] + "\t" + dt.Rows[i]["Number"]); 51 } 52 Console.ReadLine(); 53 } 54 55 } 56 57 }
其中第44行代码 DataTable dt = sqlHelper.Query("select Name, Number from Stars where Name like '%James%'").Tables[0];
%James%表示前面和后面包含零个、一个或多个数字或字符,也就是包含名字内James
运行结果如下
前言:
这一段来自SQLite官网
SQLite is an in-process library that implements a self-contained, serverless, zero-configuration, transactionalSQL database engine. The code for SQLite is in the public domain and is thus free for use for any purpose, commercial or private. SQLite is the most widely deployed database in the world with more applications than we can count, including several high-profile projects.
SQLite 是一个软件库,实现了自给自足的、无服务器的、零配置的、事务性的 SQL 数据库引擎。SQLite 源代码不受版权限制。SQLite 是在世界上最广泛部署的 SQL 数据库引擎。SQLite是世界上应用最广泛的数据库,拥有着不计其数的应用,包括备受瞩目的项目。
作者:自恋狂学长出处:http://www.cnblogs.com/zhaoliankun/本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。