0

Windowsフォームアプリケーションの構築を開始しました。ログインすると、次のコードが実行されます。しかし、問題は、ユーザーがテーブルにログインするたびにオーバーライドされることです。データベーステーブルが一度だけ作成されるようにするにはどうすればよいですか?

   SQLiteConnection sqlite_conn;
   SQLiteCommand sqlite_cmd;
   SQLiteDataReader sqlite_datareader;

   // create a new database connection:
   sqlite_conn = new SQLiteConnection("Data Source=database.db;Version=3;New=True;Compress=True;");

   sqlite_conn.Open(); 

   sqlite_cmd = sqlite_conn.CreateCommand(); 

   sqlite_cmd.CommandText = "CREATE TABLE test (id integer primary key, text varchar(100));";

   sqlite_cmd.ExecuteNonQuery();

または、それを行うより良い方法はありますか?

4

3 に答える 3

0

最初にテーブルが存在するかどうかを確認し、テーブルが存在しない場合はテーブルを作成します

IF OBJECT_ID('test', 'U') IS NULL 
BEGIN 
   CREATE TABLE test (id integer primary key, text varchar(100));
END

SQLライトの場合

create table if not exists test (id integer primary key, text varchar(100))
于 2013-07-16T15:01:03.653 に答える