使用SQL Serverce的智能设备应用 [英] Smartdevice appllication using SQL Serverce
问题描述
嗨
我想开发智能设备应用程序.将Sql ServerCe与提供程序配合使用
我该如何使用提供者与数据库连接以及需要什么(dll)来添加我的项目.
您能否解释一下使用提供程序连接数据库的每个步骤.
Hi
I want to develop the smart device application. using the Sql ServerCe with providers
how can i connect with database using of providers and what is requirement(dll) to add my project.
could you please explain each step for connect to database using of providers.
推荐答案
您的要求是:System.Data.SqlServerCe
连接公差
Your Requirement is :System.Data.SqlServerCe
Decleration of Connection
System.Data.SqlServerCe.SqlCeConnection Connection;
连接您的SqlCe
连接字符串"\\我的文档"表示我们的数据库文件必须是智能设备上的我的文档"文件夹
Connect your SqlCe
Connection String "\\My Documents " Said Our Database file Must be My Documents Folder on your Smart Device
//Con is a connection String like
String Con = "Data Source = \\My Documents";
Connection = new System.Data.SqlServerCe.SqlCeConnection(Con);
//Connect your Sql Ce
Connection.Open();
创建并执行查询
Create and Execute The Query
SqlCommand cmd = new SqlCommand("SELECT * FROM Customers",Connection);
SqlDataReader reader = cmd.ExecuteReader();
while(reader.Read()) {
Console.WriteLine("{0} - {1}",
reader.GetString(0), reader.GetString(1));
如果要使用代码创建数据库文件,则可以使用此代码
If you wanna Create your Database File With Your Code You Can Use This Code
System.Data.SqlServerCe.SqlCeEngine engine = new System.Data.SqlServerCe.SqlCeEngine("Data Source= \\My Documents");
engine.CreateDatabase();
这篇关于使用SQL Serverce的智能设备应用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!