Click here to Skip to main content
12,821,494 members (27,932 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as


8 bookmarked
Posted 29 Aug 2014

Use Local DataBase file (.sdf) in Windows Application C#

, 29 Aug 2014 CPOL
Rate this:
Please Sign up or sign in to vote.
How to use local database file (.sdf) in Windows application C#


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?

  1. Go to->Solution explorer->right click on your application->Add->New Item.

  2. Go to->Data->Local dataBase->Click on Add button.

  3. 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?

  1. Then Go To->Server Explorer->Expand your database (MyDB.sdf) ->right click on->table->Create Table.

  2. 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.

  1. If you want to insert, update, delete data from local database, you need to add this namespace in your code System.Data.SqlServerCe.
  2. Then, write this method. In this method, I have to use sqlceConnection, SqlCeCommand, SqlCeCommandBuilder.

  3. Then write Add method. In this method, I have to write insert new record in local database table.

  4. Then write Update method. In this method, I have to write updation code.

  5. Then write Delete method. In this method, I have to write delete code.

This is my complete demo.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Software Developer MNC
India India
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
Group type: Collaborative Group (No members)

You may also be interested in...


Comments and Discussions

QuestionWhere is the code for FillDataInDataset? Pin
Cesar8018-Mar-16 5:13
memberCesar8018-Mar-16 5:13 
QuestionData is not saved when values entered programmatically Pin
Anish Joy18-Jul-15 22:46
memberAnish Joy18-Jul-15 22:46 
AnswerRe: Data is not saved when values entered programmatically Pin
pritik8894-Oct-15 21:38
grouppritik8894-Oct-15 21:38 
GeneralMy vote of 2 Pin
Klaus Luedenscheidt29-Aug-14 18:06
memberKlaus Luedenscheidt29-Aug-14 18:06 
Questionsample project Pin
fredatcodeproject29-Aug-14 13:25
memberfredatcodeproject29-Aug-14 13:25 
SuggestionCode as text Pin
Mika Wendelius29-Aug-14 5:28
mentorMika Wendelius29-Aug-14 5:28 
SuggestionSQLite Pin
adriancs29-Aug-14 5:05
professionaladriancs29-Aug-14 5:05 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170308.1 | Last Updated 29 Aug 2014
Article Copyright 2014 by pritik889
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid