i'v used this code to generate sqlite Database ..
private static SQLiteConnection GenData()
{
SQLiteConnection.CreateFile("MyDatabase.sqlite");
SQLiteConnection m_dbConnection;
m_dbConnection new SQLiteConnection("Data Source=MyDatabase.sqlite;Version=3;");
m_dbConnection.Open();
string createTableQuery = @"CREATE TABLE IF NOT EXISTS [MyTable] (
[ID] INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
[Value] VARCHAR(2048) NULL
)";
SQLiteCommand command = new SQLiteCommand(createTableQuery, m_dbConnection);
command.ExecuteNonQuery();
return m_dbConnection;
}
and i use it in button click to insert Data and Create DB
private void insertintoDB(string Textbox)
{
SQLiteConnection m_dbConnection = GenData();
string sql = "insert into MyTable (Value) values ('" + Textbox + "')";
SQLiteCommand commmand = new SQLiteCommand(sql, m_dbConnection);
commmand.ExecuteNonQuery();
}
insertintoDB(textbox1.text)
and i put GenData()
in load event
but every time i use the application .. it auto Generate the database and i need it to be only one time
Aucun commentaire:
Enregistrer un commentaire