Click here to Skip to main content
Click here to Skip to main content

Tagged as

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)

Follow on   Twitter   Google+   LinkedIn

Comments and Discussions

GeneralMy vote of 2 PinmemberKlaus Luedenscheidt29-Aug-14 18:06 
Questionsample project Pinmemberfredatcodeproject29-Aug-14 13:25 
SuggestionCode as text PinmentorMika Wendelius29-Aug-14 5:28 
SuggestionSQLite Pinprofessionaladriancs29-Aug-14 5:05 

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

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

| Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.150327.1 | Last Updated 29 Aug 2014
Article Copyright 2014 by pritik889
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid