Select Values From Local Database(.sdf) Mobile Application Smart Device Visual Studio 2008 in C#

Select Values From Local Database Connection.

Retrive Values From Local Database (.sdf)(Database connection)  To Display DatagridView in Window Application Smart Device 2008 C#



using System;
using System.Linq;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

using System.Data.SqlServerCe;

namespace SmartDeviceProject1
    public partial class Form1 : Form
        public Form1()
        private void Form1_Load(object sender, EventArgs e)

        private void button1_Click_1(object sender, EventArgs e)

       SqlCeConnection con = new SqlCeConnection

 ("Data Source=" +(System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase)) + "\\AppDatabase1.sdf;Persist Security Info=False");

       SqlCeCommand cmd = new SqlCeCommand("select name from reg",con);
       SqlCeDataAdapter adp = new SqlCeDataAdapter(cmd);
       DataTable dt = new DataTable();
       dataGrid1.DataSource = dt;




First - Add Database Connection - Add - Add Reference - System.Data.SqlCeConnection.

Next  -  Inserted Table Values - Display DataGridView

Next - Design Add - Button  & DataGridview

Next - Add Namespace - Get Connection String - Retrive to Bind GridView


Post a Comment