生物技术网站开发,网站备案时核验单,常平东站是东莞东站吗,如何替换网站的图片查询SQLite数据库表中字段#xff08;列#xff09;存在的方法
使用SQL语句为#xff1a;PRAGMA table_info([DeviceTrees]); 其中“DeviceTrees”为数据库表的名称。
使用SQLite Expert Professional工具#xff0c;查看该语句是否起作用#xff0c;这里使用的版本是…查询SQLite数据库表中字段列存在的方法
使用SQL语句为PRAGMA table_info([DeviceTrees]); 其中“DeviceTrees”为数据库表的名称。
使用SQLite Expert Professional工具查看该语句是否起作用这里使用的版本是v3.1.9的。
输入语句后点击“Execute SQL”按钮后查询结果如下图所示说明该语句查询是正确的。 在C# 中通过该语句查询DeviceTrees表中所有字段列放入DataTable中通过循环判读字段列是否存在。示例代码如下所示
public bool InsertColumnGuidFunc()
{bool isExist false;try{Liststring columnList new Liststring();//查询DetectorTrees 表信息string strSql PRAGMA table_info([DeviceTrees]);;//调用SQLite数据库接口using (DataTable dt SQLiteDbHelper.ExecuteDataTable(strSql.ToString(), null)){if (dt ! null dt.Rows.Count 0){for (int i 0; i dt.Rows.Count; i){string columnName dt.Rows[i][name].ToString();columnList.Add(columnName);}}}//判断列是否存在if (columnList ! null columnList.Count 0){if (columnList.Contains(DeviceGuid))isExist true;elseisExist false;}}catch (Exception ex){}finally{}return isExist;
}
根据查询结果如果字段列存在则不进行插入字段列的操作反之则可通过sql语句向表中插入想要的字段列。
扩展
插入字段列主要语句为
alter table DeviceTrees add column [DeviceGuid] VARCHAR(100) NOT NULL DEFAULT (00000000-0000-0000-0000-000000000000); **************************************************************************************************************