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

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

 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 = http://www.mamicode.com/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数据库中、特定表中是否存在某列、