移动Windows应用程序 [英] Mobile Windows Application

查看:102
本文介绍了移动Windows应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,

我正在使用移动Windows应用程序.我设计了一些页面.我需要在数据库中存储一些数据.其给定的DataSource路径无效错误.任何人都可以帮助如何连接数据库以及如何在移动设备中安装数据库.


Hello,

I am working with mobile windows application.I designed some pages. I need to store some data in database. Its giving DataSource path is not valid error. Any one can help how to connect database and how to install database in mobile.


System.Data.SqlServerCe.SqlCeConnection con = new System.Data.SqlServerCe.SqlCeConnection("Data Source=.//Mobile.sdf");
            System.Data.SqlServerCe.SqlCeCommand com = new System.Data.SqlServerCe.SqlCeCommand("insert into Emp values(''" + textBox1.Text + "'')", con);
            con.Open();
            com.ExecuteNonQuery();
            con.Close();



在上面的代码中,我遇到了这个异常:

找不到数据库文件.检查数据库的路径. [Data Source = .//Mobile.sdf]


代码在前置"变量中被阻止[/编辑]



In the above code i am getting this exception:

The database file cannot be found. Check the path to the database. [ Data Source = .//Mobile.sdf ]


Code is blocked in "pre" tags[/Edited]

推荐答案

如果您是为WinCE 5.0-6.5开发的,则应复制database.sdf存档到您的手机中.另外,您还应该在手机上安装Microsoft SQL Server Compact Edition.

连接字符串:

数据源= database.sdf;加密数据库= True;密码= myPassword;文件模式=共享读取;持久安全信息= False;
If you develop for WinCE 5.0 - 6.5 you should copy database.sdf file into your mobile. Also you should install Microsoft SQL Server Compact Edition on your mobile.

Connection string:

Data Source=database.sdf;Encrypt Database=True;Password=myPassword;File Mode=shared read;Persist Security Info=False;


如果您正在对Windows ce 5.0进行编码-6.5并使用VS2005或VS2008进行开发,则必须将db复制到exe所在的根目录,然后使用通过获取.sdf文件的路径.
If you are coding windows ce 5.0 - 6.5 and developing using VS2005 or VS2008, then you must copy the db to the root directory where the exe is and then use use reflection to get the path of the .sdf file using

string dbPath;
            dbPath = System.Reflection.Assembly.GetExecutingAssembly().Location;
            dbPath=dbPath.Substring(0,dbPath.LastIndexOf(@"\")+1);



那么你可以使用



then you can use

System.Data.SqlServerCe.SqlCeConnection con = new System.Data.SqlServerCe.SqlCeConnection("Data Source=" + dbPath +"\Mobile.sdf");



希望这会有所帮助....



Hope this helps....


这篇关于移动Windows应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆