例如,我们需要读取users.xml中的数据,一种比较笨的方法是,将users.xml直接拷到pda上,但是这种方法并不通用,我们可以借鉴透明按钮的方法,把他作为嵌入的资源,这个所谓的嵌入的资源就是当部署的时候,会直接部署到pda上,不需要拷贝进去。
=======================================
第一种方法,我们直接拷到pda上:
=========================================
Cursor.Current = Cursors.WaitCursor;
DataSet ds = new DataSet();
ds.ReadXml((@"/users.xml"));//这时我们把users.xml存放在/下
int count = ds.Tables["user"].Rows.Count;//看表中有多少个user
operateData.createFile("MobileLawEn.sdf");
if (ds != null && count > 0)
{
checkTableExistance("users");
SqlCeConnection conn = new SqlCeConnection(operateData.connStr);
SqlCeCommand cmd = new SqlCeCommand(
"create table users(username nvarchar(20),password nvarchar(20),deptid int,constraint p_key primary key(username,deptid))", conn);
conn.Open();
int rst = cmd.ExecuteNonQuery();
Cursor.Current = Cursors.Default;
for (int i = 0; i < count; i++)
{
string name = ds.Tables["user"].Rows[i]["username"].ToString();
//读取第i个user中的用户名
string password = ds.Tables["user"].Rows[i]["password"].ToString();
string deptid = ds.Tables["user"].Rows[i]["deptid"].ToString();
string sql = "insert into users (username,password,deptid) values ('" + name + "','" + password + "'," + deptid + ")";
SqlCeCommand comm = new SqlCeCommand(sql, conn);
comm.ExecuteNonQuery();
}
conn.Close();
Cursor.Current = Cursors.Default;
============================================
第二种方法:我们将xml文件作为嵌入的资源:
=============================================
首先嵌入:
Cursor.Current = Cursors.WaitCursor;
DataSet ds = null;
ds = new DataSet();
System.IO.Stream strm = System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream("MobileLawEn.xml.users.xml");
//GetManifestResourceStream是用来加载制定的资源。
ds.ReadXml(strm, System.Data.XmlReadMode.InferSchema);
//System.Data.XmlReadMode.InferSchema用来设置这种模式:
InferSchema
|
忽略任何嵌入式架构,并从 XML 数据推断架构
|
int count = ds.Tables["user"].Rows.Count;//看表中有多少个user
operateData.createFile("MobileLawEn.sdf");
if (ds != null && count > 0)
{
checkTableExistance("users");
SqlCeConnection conn = new SqlCeConnection(operateData.connStr);
SqlCeCommand cmd = new SqlCeCommand(
"create table users(username nvarchar(20),password nvarchar(20),deptid int,constraint p_key primary key(username,deptid))", conn);
conn.Open();
int rst = cmd.ExecuteNonQuery();
Cursor.Current = Cursors.Default;
for (int i = 0; i < count; i++)
{
string name = ds.Tables["user"].Rows[i]["username"].ToString();//读取第i个user中的用户名
string password = ds.Tables["user"].Rows[i]["password"].ToString();
//读取第i个user中的密码
string deptid = ds.Tables["user"].Rows[i]["deptid"].ToString();
string sql = "insert into users (username,password,deptid) values ('" + name + "','" + password + "'," + deptid + ")";
SqlCeCommand comm = new SqlCeCommand(sql, conn);
comm.ExecuteNonQuery();
}
conn.Close();
Cursor.Current = Cursors.Default;
相关推荐
Often Pocket PC programs need a background process and most of existing Pocket PC programs implement it by creating an executable file which is started during system start-up. But Pocket PC has 32 ...
This book is both a tutorial and reference guide for writing network applications on Pocket PC 2002 and Pocket PC Phone Edition devices. The term network application does not limit the scope of this ...
VS2008 Pocket PC 2003 SE仿真程序上网设置
文档明确描述如何使用非 Microsoft 基础类 MFC Win 32 应用程序中 SHFullScreen API 来创建 PocketPC 上全屏窗口。 但是, 文档未介绍相同过程基于 MFC 的应用程序。 本文介绍如何通过使用 Win32API 或 MFC 进行全 ...
被文档介绍了在VS2005+ActiveSync+PPC环境下如何正确配置使模拟器Pocket PC上网的说明。
Pocket PC 2003 PDA简易通讯录用VS2008 c#语言做 符合团队开发标准
在Pocket PC中建立GPRS连接的原代码(c++)
实战Pocket PC程序设计 详解介绍了 Pocket PC程序设计的主要方面,适合熟悉桌面开发,想进行 Pocket PC手机程序设计的入门者了解PocketPC 开发与桌面的主要不同,这个是中文版
这是一个基于WinCE Pocket PC,用C#开发出来的手机小游戏,占用空间下,可供休闲娱乐
基于PocketPC的汉字输入系统的设计与实现 对设计输入法有一定的理论指导作用。
简单易懂轻松用c#语言中实现 pad 或pocket pc 的键盘的隐藏和显示
本软件是基于Pocket PC、手持设备和手机上的掌上水准测量程序,解决外业水准测量的记录问题,程序能根据观测等级、仪器类型按规范要求的观测顺序自动移动光标位置,自动完成计算并根据各限差要求对超限数据提醒;...
在Pocket PC开发中使用函数拨号的方法。
Google Map for Pocket PC,本文件为CAB安装包,直接拷贝到Pocket PC上然后运行就可以了。
在Pocket PC中使用Web Service连接数据库
把下載的文件Copy 入Pocket pc 內執行 2. 解壓estock.zip 把 estock.vb 及 bmp資料夾 複製到 你的Pocket PC 任何一個資料夾下 把 estock.mdb 複製到pcoket pc的 \my documents 下 3. 執行estock.vb 便...
PocketPC下PocketPC下的俄罗斯方块游戏的俄罗斯方块游戏PocketPC下的俄罗斯方块游戏PocketPC下的俄罗斯方块游戏PocketPC下的俄罗斯方块游戏
本文介绍配置Pocket PC 2003 SE设备仿真器网络设置的方法共有六个步骤,通过配置可以实现PDA上网。
打造POCKET PC 2002 Emulator的中文环境
Pocket PC 充电监视器 (Pocket PC 掌上助手)是针对Pocket PC开发的一款免费的电池监视软件,在使用 ActiveSync 连接掌上设备时,可以自动检测出电源电量,充电状态并直接在Windows状态栏中显示。