c# 連接本地的sdf數據庫文件


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlServerCe; //SDF  是ce版本,要使用該驅動才行
 
namespace testc
{
    public partial class Form1 : Form
    {
        SqlCeConnection sqlceCon = new SqlCeConnection();     //SqlCeConnection 
        SqlCeCommand sqlCeCom = new SqlCeCommand();
        DataTable dt = new DataTable();
 
        public Form1()
        {
            InitializeComponent();
        }
 
        private void Form1_Load(object sender, EventArgs e)
        {
            sqlceCon = new SqlCeConnection("Data Source=C:\\Northwind.sdf");
            sqlceCon.Open();
 
            SqlCeDataAdapter adptrOdbc = new SqlCeDataAdapter("select * from customers", sqlceCon);
            adptrOdbc.Fill(dt);
 
            dataGridView1.DataSource = dt;
        }      
    }
}


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM