我对 C# 很陌生,我正在尝试创建一个 sqlite 数据库连接类。我通过单击我的项目名称 > 添加 > 类创建了一个新的类文件。我在这个文件中有以下代码。
问题是我在之后的每一行都出现错误SQLiteDataReader
- 如果我将鼠标悬停在上面,
sqlite_conn
那么它会说'......是一个字段,但用作类型' - 如果我将鼠标悬停在
SQLiteConnection
上面,它会说...方法必须有一个返回类型 - 如果我将鼠标悬停在上面,
("Data Source=database.db;Version=3;New=True;Compress=True;")
那么它会说 Type expected
`
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Finisar.SQLite;
namespace learningCsharp
{
class database
{
// We use these three SQLite objects:
SQLiteConnection sqlite_conn;
SQLiteCommand sqlite_cmd;
SQLiteDataReader sqlite_datareader;
// Getting error in every lines after this
// create a new database connection:
sqlite_conn = new SQLiteConnection("Data Source=database.db;Version=3;New=True;Compress=True;");
//open the connection:
sqlite_conn.Open();
// create a new SQL command:
sqlite_cmd = sqlite_conn.CreateCommand();
}
}
你能帮我解决这个问题并创建一个有效的sqlite数据库连接类吗?