ローカルデータベース、いくつかの例が必要です 質問する

ローカルデータベース、いくつかの例が必要です 質問する

複数のコンピューターにインストールして実行するアプリを作成しています。目標は、アプリとともにインストールされる空のローカル データベース ファイルを作成し、ユーザーがアプリを使用すると、そのデータベースにアプリのデータが入力されるようにすることです。次の例を挙げていただけますか。

  1. アプリがローカルデータベースに接続できるようにするには何をする必要がありますか
  2. アプリから変数を使用してクエリを実行する方法 たとえば、次のものをデータベースに追加するにはどうすればよいでしょうか

    String abc = "ABC";
    String BBB = "Something longer than abc";
    

などなど編集::「追加 > 新しいアイテム > ローカルデータベース」から作成した「ローカルデータベース」を使用していますが、それに接続するにはどうすればいいでしょうか? 馬鹿げた質問で申し訳ありません。.net でデータベースを使用したことがありません。

ベストアンサー1

ニーズに応じて、Sql CE も検討できます。使用を検討しているデータベース、または要件を指定すれば、接続文字列などの適切で実際の例が得られるはずです。

編集: SqlCe / Sql Compactのコードはこちら

    public void ConnectListAndSaveSQLCompactExample()
    {
        // Create a connection to the file datafile.sdf in the program folder
        string dbfile = new System.IO.FileInfo(System.Reflection.Assembly.GetExecutingAssembly().Location).DirectoryName + "\\datafile.sdf";
        SqlCeConnection connection = new SqlCeConnection("datasource=" + dbfile);

        // Read all rows from the table test_table into a dataset (note, the adapter automatically opens the connection)
        SqlCeDataAdapter adapter = new SqlCeDataAdapter("select * from test_table", connection);
        DataSet data = new DataSet();
        adapter.Fill(data);

        // Add a row to the test_table (assume that table consists of a text column)
        data.Tables[0].Rows.Add(new object[] { "New row added by code" });

        // Save data back to the databasefile
        adapter.Update(data);

        // Close 
        connection.Close();
    }

System.Data.SqlServerCeへの参照を追加することを忘れないでください

おすすめ記事