Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Local database, I need some examples

Tags:

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 :

  1. what do I need to do so my app can connect to its local database
  2. 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

like image 937
Nikola Sivkov Avatar asked Jul 13 '09 20:07

Nikola Sivkov


People also ask

What is a local machine database?

Local Database means a local copy of a database that contains Classifications of certain Data Types, and which is downloaded by Partner via the SDK.

What is database given an example?

Some examples of popular database software or DBMSs include MySQL, Microsoft Access, Microsoft SQL Server, FileMaker Pro, Oracle Database, and dBASE.


2 Answers

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

like image 76
sindre j Avatar answered Sep 20 '22 12:09

sindre j


I'm not seeing anybody suggesting SQL Compact; it's similar to SQLite in that it doesn't require installation and tailors to the low-end database. It grew out of SQL Mobile and as such has a small footprint and limited feature-set, but if you're familiar with Microsoft's SQL offerings it should have some familiarity.

SQL Express is another option, but be aware that it requires a standalone installation and is a bit beefier than you might need for an applciation's local cache. That said it's also quite a bit more powerful than SQL Compact or SQLite.

like image 26
STW Avatar answered Sep 22 '22 12:09

STW