【急】SQL Server数据导入Compact数据库

anbin0814 2012-07-27 01:44:46

private static void CopyTable(SqlConnection sqlConn, SqlCeConnection ceConn, string queryString, string destTableName, bool delTalbe)
{
sqlConn.Open();
ceConn.Open();
SqlCommand sqlCmd = sqlConn.CreateCommand();
sqlCmd.CommandText = queryString;

SqlCeCommand ceCmd = ceConn.CreateCommand();
ceCmd.CommandType = CommandType.TableDirect;
ceCmd.CommandText = destTableName;

SqlDataReader sqlReader = sqlCmd.ExecuteReader();

SqlCeResultSet resultSet = ceCmd.ExecuteResultSet(
ResultSetOptions.Sensitive | //检测对数据源所做的更改
ResultSetOptions.Scrollable | //可以向前或向后滚动
ResultSetOptions.Updatable); //允许更新数据

if (delTalbe)
{
string sql = "delete " + destTableName;

SqlCeCommand cmd = ceConn.CreateCommand();
cmd.CommandText = sql;
cmd.ExecuteNonQuery();
}

object[] values;

SqlCeUpdatableRecord record;

while (sqlReader.Read())
{
//从源数据库表中读取数据
values = new object[sqlReader.FieldCount];
sqlReader.GetValues(values);

//把数据写入到Conpact数据库
record = resultSet.CreateRecord();
record.SetValues(values);
resultSet.Insert(record);
}

sqlReader.Close();
resultSet.Close();

sqlConn.Close();
ceConn.Close();

}



CREATE TABLE [dbo].[test](
[id] [int] NOT NULL,
[order] [int] NULL,
CONSTRAINT [PK_test] PRIMARY KEY CLUSTERED )



resultSet.Insert(record);这句老是报错 Unspecified error [ test ]

"SQL Server Compact ADO.NET Data Provider"
" at System.Data.SqlServerCe.SqlCeDataReader.ProcessResults(Int32 hr)\r\n at System.Data.SqlServerCe.SqlCeResultSet.SetValues(SEPREPAREMODE mode, SqlCeUpdatableRecord record)\r\n at System.Data.SqlServerCe.SqlCeResultSet.InternalInsert(Boolean fMoveTo, Object sender, SqlCeUpdatableRecord record)\r\n at System.Data.SqlServerCe.SqlCeResultSet.Insert(SqlCeUpdatableRecord record)\r\n at SmartMobileDevice.DAL.DataSynTools.CopyTable(SqlConnection sqlConn, SqlCeConnection ceConn, String queryString, String destTableName, Boolean delTalbe)\r\n at SmartMobileDevice.DAL.DataSynTools.Syn()\r\n at SmartMobileDevice.Login.button1_Click(Object sender, EventArgs e)\r\n at System.Windows.Forms.Control.OnClick(EventArgs e)\r\n at System.Windows.Forms.Button.OnClick(EventArgs e)\r\n at System.Windows.Forms.ButtonBase.WnProc(WM wm, Int32 wParam, Int32 lParam)\r\n at System.Windows.Forms.Control._InternalWnProc(WM wm, Int32 wParam, Int32 lParam)\r\n at Microsoft.AGL.Forms.EVL.EnterMainLoop(IntPtr hwnMain)\r\n at System.Windows.Forms.Application.Run(Form fm)\r\n at SmartMobileDevice.Program.Main()\r\n"
...全文
81 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复
经常搞网站开发或者数据分析人的估计天天离不开数据了,目前市面上的数据产品非常繁多,比如本站博客上也发布的有 Navicat Premium 中文版,但是要找一款兼容各类数据管理工具,也不是很难,借助 Database .NET 就可以简便地查看,管理数据。Database .NET 中文版是一个免费多重数据管理工具,提供更简单方便的可视化界面浏览数据内容,无须另外安装整个数据系统,即可直接本地或远程进行数据的在线存取,方便数据调试,修改,查询,打印,输出,备份等多方面处理。 Database .NET 中文版 Database .NET 中文版 Database .NET 支持数据种类 MS Access 97-2003 (*.mdb;*.*) MS Access 2007 (*.accdb) MS Excel 97-2003 (*.xls) MS Excel 2007 (*.xlsx) Firebird (*.gdb;*.fdb) MySQL 5.x or later SQL Server SQL Server CE 3.5sp1 (*.sdf) SQLite (*.db;*.db3;*.sqlite) PostgreSQL Oracle dBASE IV (*.dbf) Database .NET 中文版特色功能 整合支持多种数据平台,单一文件方便携带与使用 支持语法高亮显示(Syntax Highlighting) 数据自动化处理(Automatically): 无须通过SQL命令或外部执行 密码保护(Protect Database): Access 97-2003/Access 2007/SQL Server CE/SQLite 自动新建(Create Database): Access 2000/Access 2007/Firebird/SQL Server CE/SQLite 自动压缩(Shrink Database): Access 97-2003/Access 2007/Firebird/MySQL(MyISAM)/SQL Server/SQL Server CE/SQLite/PostgreSQL 备份还原(Backup/Restore Database): MySQL/SQL Server/PostgreSQL 支持代码自动生成(Code Generation): Access/Firebird/MySQL/Oracle/PostgreSQL/SQL Server/SQL Server CE/SQLite 支持数据服务管理(Service Manager): Firebird/MySQL/PostgreSQL/SQL Server 支持多页签查询(Multiple Query Tab), 多页签结果显示(Multiple Result) 支持范例文件管理(SQL Example Manager) 支持拖放数据加载(DragDrop Database) 结果输出(Export to CSV/XML/TXT) 多国语言显示(Multiple Language): 预设中英文,并可自行扩充 结果打印(Print query results) Database .NET 中文版是一款台湾软件厂商开发的,支持多重数据管理工具,支持市面上的大多数数据系统:例如 Microsoft Access、Generic ODBC、SQL Server、LocalDB、SQL Server Compact、SQL Azure、MySQL、Oracle、Sybase ASE 等等。 Database .NET 中文版 也支持包含数据对象浏览,数据表与索引编修,数据列编辑,SQL分析与调试,脚本生成,图像化,打印,导入,输出等多方面处理。欢迎数据爱好者下载使用。而且该数据管理工具也是提供免费使用,支持免安装,简单易用,支持多国语言,支持 Windows XP/2003/Vista/2008/7/8/10/2012 (x86/x64)等系统平台,但是该应用软件需求.NET 4.x以上的环境要求

19,498

社区成员

发帖
与我相关
我的任务
社区描述
硬件/嵌入开发 嵌入开发(WinCE)
社区管理员
  • 嵌入开发(WinCE)社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧