navicat创建SQLite数据库和数据表C#没法连接
要在C#中连接Navicat创建的SQLite数据库和数据表,可以使用System.Data.SQLite命名空间中的SQLiteConnection和SQLiteCommand类。
首先,确保已经安装了System.Data.SQLite NuGet包。
然后,可以使用以下代码示例来连接Navicat创建的SQLite数据库和数据表:
using System.Data.SQLite;
public class SQLiteHelper
{
private SQLiteConnection connection;
public SQLiteHelper(string databasePath)
{
connection = new SQLiteConnection("Data Source=" + databasePath);
connection.Open();
}
public void CreateTable(string tableName, string columns)
{
string query = "CREATE TABLE IF NOT EXISTS " + tableName + " (" + columns + ")";
using (SQLiteCommand command = new SQLiteCommand(query, connection))
{
command.ExecuteNonQuery();
}
}
// 其他数据库操作方法...
}
使用示例:
string databasePath = "your_database_path";
SQLiteHelper helper = new SQLiteHelper(databasePath);
string tableName = "your_table_name";
string columns = "id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT, age INTEGER";
helper.CreateTable(tableName, columns);
// 其他数据库操作...
请确保将"your_database_path"替换为SQLite数据库文件的实际路径,"your_table_name"替换为要操作的数据表名称,"columns"替换为要创建的数据表的列定义
原文地址: https://www.cveoy.top/t/topic/hCGa 著作权归作者所有。请勿转载和采集!