首先需要添加using System.Data.SqlServerCe; 引用,sdf属于SQL Server CE版本
SqlCeConnection cc = new SqlCeConnection(); DataTable dt = new DataTable(); private void button1_Click(object sender, EventArgs e) { cc = new SqlCeConnection("Data Source=Database1.sdf;password=123"); cc.Open(); SqlCeDataAdapter ada = new SqlCeDataAdapter("select * from aa", cc); ada.Fill(dt); }
如果sdf没设置密码可以将password去掉