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 = 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();
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。