设为首页 加入收藏

TOP

SQLite(轻量级最佳数据库) 原理分析和开发应用 (四)
2014-11-24 01:22:06 来源: 作者: 【 】 浏览:23
Tags:SQLite 轻量级 最佳 数据库 原理 分析 开发 应用
PrepareCommand(command, conn, cmdText, parameters);

055 SQLiteDataAdapter da = new SQLiteDataAdapter(command);

056 da.Fill(ds);

057 return ds;

058 }

059 }

060 }

061 }

062

063 public static int ExecuteNonQuery(string cmdText, List parameters)

064 {

065 lock (lockObject)

066 {

067 using (SQLiteConnection conn = new SQLiteConnection(ConnectionString))

068 {

069 using (SQLiteCommand command = new SQLiteCommand())

070 {

071

072 PrepareCommand(command, conn, cmdText, parameters);

073 return command.ExecuteNonQuery();

074 }

075 }

076 }

077 }

078

079 public static SQLiteDataReader ExecuteReader(string cmdText, List parameters)

080 {

081 lock (lockObject)

082 {

083 SQLiteConnection conn = new SQLiteConnection(ConnectionString);

084

085 SQLiteCommand command = new SQLiteCommand();

086

087 PrepareCommand(command, conn, cmdText, parameters);

088 SQLiteDataReader sqLiteDataReader = command.ExecuteReader();

089 return sqLiteDataReader;

090 }

091 }

092

093 public static object ExecuteScalar(string cmdText, List parameters)

094 {

095 lock (lockObject)

096 {

097 using (SQLiteConnection conn = new SQLiteConnection(ConnectionString))

098 {

099 using (SQLiteCommand command = new SQLiteCommand())

100 {

101 PrepareCommand(command, conn, cmdText, parameters);

102 return command.ExecuteScalar();

103 }

104 }

105 }

106 }

107 public static void CreateDataBase()

108 {

109 if (!File.Exists(DataBasePath))

110 SQLiteConnection.CreateFile(DataBasePath);

111 CreateTable();

112 }

113

114

115 public static void CreateTable()

116 {

117 ExecuteNonQuery(CodeDetailTabale, null);

118 }

119

120

121 private static string CodeDetailTabale

122 {

123 get

124 {

125 return @"CREATE TABLE [CodeDetail] (

126 [CdType] [nvarchar] (10) NOT NULL ,

127 [CdCode] [nvarchar] (20) NOT NULL ,

128 [CdString1] [ntext] NOT NULL ,

129 [CdString2] [ntext] NOT NULL ,

130 [CdString3] [ntext] NOT NULL,

131 PRIMARY KEY (CdType,CdCode)

132 ) ;";

133 }

134 }

135 }

136 }

示例讲解

A、使用到自己定义的锁private static object lockObject = new object();

B、使用完连接后都进行关闭操作。使用了using

C、创建数据库命令:SQLiteConnection.CreateFile(DataBasePath);

最后再讲解个Insert or Replace into的经典用法
1 Insert or Replace INTO User(ID, Name,Age) Select old.ID,new.Na

首页 上一页 1 2 3 4 下一页 尾页 4/4/4
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇如何把数据导入不同的表空间 下一篇将SQLite中的数据转换为Excel表

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: