Introduction
Here, I will explain how to use .SDF local database file in your Windows application. I will also explain how to save record and update record in local database. I will explain these points:
- How to add Sdf file in application?
- How to create table in SDF Database?
- How to save data in SDF database table?
Step 1: How to Add Sdf File in Application?
- Go to->Solution explorer->right click on your application->Add->New Item.
- Go to->Data->Local dataBase->Click on Add button.
- Then go to->view menu->Server Explorer.
Here, you can see the local database which is created by you.
Step 2: How to Create Table in SDF Database?
- Then Go To->Server Explorer->Expand your database (MyDB.sdf) ->right click on->table->Create Table.
- Write your table name and add column name and column data type, length, etc. and click OK.
In this screen, my table name and my column name.
Step 3: How to Save Data in SDF Database Table?
I will use sqlserverce
namespace.
Here I will insert
, update
, delete
data from datatable which reflect in actual database table.
- If you want to insert, update, delete data from local database, you need to add this namespace in your code
System.Data.SqlServerCe
. - Then, write this method. In this method, I have to use
sqlceConnection
, SqlCeCommand
, SqlCeCommandBuilder
.
- Then write
Add
method. In this method, I have to write insert new record in local database table.
- Then write
Update
method. In this method, I have to write updation code.
- Then write
Delete
method. In this method, I have to write delete code.
This is my complete demo.
I am C# corner MVP and Blogger and currently working as a .Net Developer in an MNC Company India and have one and eight month experience in C#,ASP.NET,SQL server.I am a B.Tech in computer science.This is My Blog where i blog https://aspdotnetmyblog.com/