如何使用c#.net在Sqllite中创建连接已创建的数据库 [英] How to make connection already created database in Sqllite using c#.net
本文介绍了如何使用c#.net在Sqllite中创建连接已创建的数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
我是新的sqlite,数据库没有再次更新新创建的和当前值,但我想使用已经使用sqlite或更新的数据库相同的数据库,对于dat如何使用c#创建连接可以指导我或发送片段'
Hi All ,
I am new sqlite ,The databse is not updating again new created and current values, but i want to use already db using sqlite or update same db , for dat how to create connection with c# can u guide me or send snippets'
SQLiteConnection sqlite_conn;
SQLiteCommand sqlite_cmd;
SQLiteDataReader sqlite_datareader;
// create a new database connection:
sqlite_conn = new SQLiteConnection("Data Source=database1.db;Version=3;New=True;Compress=True;");
// open the connection:
sqlite_conn.Open();
// create a new SQL command:
sqlite_cmd = sqlite_conn.CreateCommand();
// Let the SQLiteCommand object know our SQL-Query:
sqlite_cmd.CommandText = "CREATE TABLE test (id integer primary key, text varchar(100));";
// Now lets execute the SQL ;D
sqlite_cmd.ExecuteNonQuery();
// Lets insert something into our new table:
sqlite_cmd.CommandText = "INSERT INTO test (id, text) VALUES (6, 'Test Text 7');";
// And execute this again ;D
sqlite_cmd.ExecuteNonQuery();
// ...and inserting another line:
sqlite_cmd.CommandText = "INSERT INTO test (id, text) VALUES (7, 'Test Text 2788');";
// And execute this again ;D
sqlite_cmd.ExecuteNonQuery();
sqlite_cmd.CommandText = "SELECT * FROM test";
sqlite_datareader = sqlite_cmd.ExecuteReader();
while (sqlite_datareader.Read())
{
MessageBox.Show(sqlite_datareader["text"].ToString());
System.Console.WriteLine(sqlite_datareader["text"]);
}
// We are ready, now lets cleanup and close our connection:
sqlite_conn.Close();
推荐答案
你可以阅读这篇文章 - 在C#应用程序中使用SQLite [ ^ ]
you can read this article - Using SQLite in your C# Application[^]
这篇关于如何使用c#.net在Sqllite中创建连接已创建的数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文