How to use local database in c #?

I created a local database for a C # project: This is the local database I mean.

I know the basic SQL commands, but did not work with databases in C #. What I would like to know specifically:

  • How to read from the database (request)
  • How to add and update rows

The database consists of only 3 tables, so I don’t think you need something interesting.

+4
source share
3 answers

First, you should learn a little about the various technologies and APIs for connecting to the database.

A more traditional method is ADO.NET, which allows you to easily define connections and execute SQL queries or stored procedures. I recommend fetching a basic ADO.NET tutorial using Google, which may differ depending on what type of project you are creating (web application, console, WinForms, etc.).

Now ORM days are becoming more popular. They allow you to define your model of the object in the code (for example, each database table will be a class, and the columns will be the properties of this class) and bind to an existing database. To add a new row to the table, you simply create an instance of the class and call the Save method when you are done.

The .NET framework has LINQ to SQL and Entity Framework for this type of template, both of which have many online tutorials. An open source project that I really like is Castle Active Record, which is built on top of NHibernate. This simplifies the definition of ORM.

If you have specific questions about any of the above issues, feel free to post a new question with more specific queries. Good luck

Update:

I thought I would add another link, because it seems that you might be interested in working with local database repositories rather than creating a client-server application. SQLite allows you to interact with local repositories in the file system through SQL code. There's also a .NET binding supported by the SQLite guys (which theoretically allows you to work with the other platforms I mentioned): http://system.data.sqlite.org/index.html/doc/trunk/www/index.wiki

+8
source

You can use SQLCE.

This blog will give you a good start.

http://weblogs.asp.net/scottgu/archive/2011/01/11/vs-2010-sp1-and-sql-ce.aspx

+2
source

Here is a short tutorial that should be useful for you.

You can use SqlDataReader to read data.

and SqlCommand to insert the update. Remove rows from your tables.

http://www.dotnetperls.com/sqlclient

0
source

All Articles