sqlite数据库创建、数据表增删改之C#设计笔记(二)

1、下载System.Data.SQLite.dll,并在项目引用该dll。
2、数据库创建:
void createNewDatabase(string sqlitePath)
{
if (!File.Exists(sqlitePath))
{
SQLiteConnection.CreateFile(sqlitePath);
}
}
3、数据表创建:
void createChildTable(string sql,string tableName)
{
if (IsTableExist(tableName))
{
SQLiteCommand command = new SQLiteCommand(sql, m_dbConnection);
command.ExecuteNonQuery();
}
}
4、数据库连接:
SQLiteConnection m_dbConnection;
void connectToDatabase()
{
m_dbConnection = new SQLiteConnection(“Data Source=MyDatabase.sqlite;Version=3;”);
m_dbConnection.Open();
}
5、数据表是否存在判断
private bool IsTableExist(string tablename)
{
SQLiteCommand command = new SQLiteCommand(“SELECT COUNT(*) FROM sqlite_master where type=‘table’ and name='”+ tablenam

你可能感兴趣的:(C#,sqllite数据库,数据库,sqlite,c#)