sqlite 判断表字段是否存在

///

/// 判断表中某个字段是否存在

///

/// 字段名

/// 表名

///

bool isExistField(string fieldName,string tableName)

{

string sql = "select sql from sqlite_master where tbl_name = '" + tableName + "' and type = 'table'";

List list = new List();

 

//开始查询数据库

bool r = false;

SQLiteCommand command = new SQLiteCommand(sql, _dbConnection);

SQLiteDataReader reader = command.ExecuteReader();

while (reader.Read())

{

r = reader["sql"].ToString().Contains(fieldName);

NLog.LogManager.GetCurrentClassLogger().Trace("sql=" + reader["sql"].ToString());

break;

}

 

reader.Close();

 

return r;

}

 

 

你可能感兴趣的:(sqlite)