码迷,mamicode.com
首页 > 数据库 > 详细

C#对现有sqlite数据库中、特定表中是否存在某列、

时间:2014-11-05 16:44:25      阅读:146      评论:0      收藏:0      [点我收藏+]

标签:style   blog   io   color   ar   os   for   sp   数据   

 1 System.Data.SQLite.SQLiteConnection conne = new System.Data.SQLite.SQLiteConnection();
 2 System.Data.SQLite.SQLiteConnectionStringBuilder connstr = new System.Data.SQLite.SQLiteConnectionStringBuilder();
 3 connstr.DataSource = System.AppDomain.CurrentDomain.BaseDirectory + "//DB//Course.db";
 4 conne.ConnectionString = connstr.ToString();
 5 conne.Open();
 6 
 7 System.Data.SQLite.SQLiteCommand cmd = new System.Data.SQLite.SQLiteCommand();
 8 
 9 string sql = "Select * From UserLoginInfo WHERE UserAccount =‘-------‘";
10 cmd.CommandText = sql;
11 cmd.Connection = conne;
12 
13 System.Data.SQLite.SQLiteDataAdapter adapter = new System.Data.SQLite.SQLiteDataAdapter(cmd);
14 DataSet data = new DataSet();
15 adapter.Fill(data);
16 DataTable table = data.Tables[0];
17 
18 bool HasShowAccount = false;
19 for (int i = 0; i < table.Columns.Count; i++)
20 {
21     if (table.Columns[i].ColumnName.Equals("ShowAccount"))
22     {
23         HasShowAccount = true;
24     }
25 }
26 
27 if (!HasShowAccount)
28 {
29     sql = "alter table UserLoginInfo add column ShowAccount CHAR(50)";
30     cmd.CommandText = sql;
31     cmd.ExecuteNonQuery();
32 }
33 conne.Close();

 

C#对现有sqlite数据库中、特定表中是否存在某列、

标签:style   blog   io   color   ar   os   for   sp   数据   

原文地址:http://www.cnblogs.com/lllqss/p/4076535.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!