Click here to Skip to main content
15,883,531 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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'


C#
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();
Posted
Updated 23-Dec-13 0:41am
v3

1 solution

you can read this article - Using SQLite in your C# Application[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900