我一直在使用操作 SQLite 数据库的 C# 应用程序,直到昨天它工作正常,它正在检索记录,
但是从昨晚开始,连接字符串返回Data Source = null
下面是测试代码:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SQLite;
namespace SQLiteTest
{
public partial class Form1 : Form
{
//string connection_string = "Data Source=UrduDictionary";
string connection_string = "Data Source=" + Environment.CurrentDirectory + "\\Test.sqlite";
string query = "";
private SQLiteConnection _connection;
private SQLiteCommand _command;
private SQLiteDataAdapter _adapter;
DataSet local;
public Form1()
{
InitializeComponent();
}
void Make_Connection()
{
_connection = new SQLiteConnection(connection_string);
}
private void button1_Click(object sender, EventArgs e)
{
Make_Connection();
}
}
下面是在监 window 口中调试时看到的图像..
我使用的库是 "SQLite-1.0.66.0-setup.exe"
我已经用其他创建的数据库进行了测试,但结果相同,任何人都可以提供帮助吗?
最佳答案
这是我做的:
private void button2_Click(object sender, EventArgs e)
{
string dbPath = Path.Combine(Environment.CurrentDirectory, "UrduDictionary");
string connString = string.Format("Data Source={0}", dbPath);
using (SQLiteConnection conn = new SQLiteConnection(connString))
{
StringBuilder query = new StringBuilder();
query.Append("SELECT * ");
query.Append("FROM CATIGORY_TABLE ");
using (SQLiteCommand cmd = new SQLiteCommand(query.ToString(), conn))
{
conn.Open();
using (SQLiteDataReader dr = cmd.ExecuteReader())
{
while (dr.Read())
{
Console.WriteLine("{0} {1} {2}",
dr.GetValue(0),
dr.GetValue(1),
dr.GetValue(2));
}
}
}
}
}
关于c# - SQLite 连接在 C# 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26646399/