Local database, I need some examples

c#, database

Solution

Depending on the needs you could also consider Sql CE. I'm sure that if you specified the database you're thinking of using, or your requirements if you're usure you would get proper and real examples of connection strings etc.

Edit: Here's code for 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();
    }

Remember to add a reference to System.Data.SqlServerCe

Problem

I'm making an app that will be installed and run on multiple computers, my target is to make an empty local database file that is installed with the app and when user uses the app his database to be filled with the data from the app . can you provide me with the following examples : - what do I need to do so my app can connect to its local database how to execute a query with variables from the app for example how would you add to the database the following thing ``` String abc = "ABC"; String BBB = "Something longer than abc"; ``` and etc Edit :: I am using a "local database" created from " add > new item > Local database" so how would i connect to that ? Sorry for the dumb question .. i have never used databases in .net

Original source