我想連接到SQLite數據庫。請給我示例代碼哪些工作。此外,我想用database.I用這個代碼鏈接datagridview的,但它不工作:如何將C#應用程序連接到SQLite數據庫
private DataTable dt;
public Form1()
{
InitializeComponent();
this.dt = new DataTable();
}
private SQLiteConnection SQLiteConnection;
private void DataClass()
{
SQLiteConnection = new SQLiteConnection("Data Source=PasswordManager.s3db;Version=3;");
}
private void GetData()
{
SQLiteDataAdapter DataAdapter;
try
{
SQLiteCommand cmd;
SQLiteConnection.Open(); //Initiate connection to the db
cmd = SQLiteConnection.CreateCommand();
cmd.CommandText = "select*from PasswordManager;"; //set the passed query
DataAdapter = new SQLiteDataAdapter(cmd);
DataAdapter.Fill(dt); //fill the datasource
dataGridView1.DataSource = dt;
}
catch(SQLiteException ex)
{
//Add your exception code here.
}
SQLiteConnection.Close();
你到目前爲止嘗試過什麼?此外,請參閱[這個問題](http://stackoverflow.com/questions/26020/what-is-the-best-way-to-connect-and-use-a-sqlite-database-from-c-sharp) – 2012-01-15 13:47:15
你有[google搜索](https://www.google.com/?#q=c%23%20sqlite%20example)嗎? – Jon 2012-01-15 13:48:07