当前位置:首页 > 网络编程 > WEB编程 > ASP.net >  操作 SQL Server Mobile 2005 数据库的常用 C# 代码 (2)

 操作 SQL Server Mobile 2005 数据库的常用 C# 代码 (2)

点击次数:29 次 发布日期:2008-11-26 12:26:28 作者:源代码网
源代码网推荐      // 跟 SQL Server 数据库进行同步
源代码网推荐  repl.Synchronize();
源代码网推荐  
源代码网推荐  // 清理 repl 对象
源代码网推荐  repl.Dispose();
源代码网推荐  
源代码网推荐  6. 远程数据访问(RDA)
源代码网推荐  // 远程数据访问
源代码网推荐  // 实例化并配置 SqlCeRemoteDataAccess 对象
源代码网推荐  SqlCeRemoteDataAccess rda = new SqlCeRemoteDataAccess();
源代码网推荐  rda.InternetUrl = "http://www.adventure-works.com/sqlmobile/sqlcesa30.dll";
源代码网推荐  rda.InternetLogin = "MyInternetLogin";
源代码网推荐  rda.InternetPassword = "<password>";
源代码网推荐  rda.LocalConnectionString = "Data Source=MyDatabase.sdf";
源代码网推荐  
源代码网推荐  // 从 SQL Server 下载数据
源代码网推荐  rda.Pull(
源代码网推荐   "Employees",
源代码网推荐   "SELECT * FROM DimEmployee",
源代码网推荐   "Provider=sqloledb;server=MySqlServer;database=AdventureWorks;uid=sa;pwd=;",
源代码网推荐   RdaTrackOption.TrackingOnWithIndexes,
源代码网推荐   "ErrorTable");
源代码网推荐  
源代码网推荐  //
源代码网推荐  // 修改本地数据
源代码网推荐  //
源代码网推荐  
源代码网推荐  // 将已修改的数据上传到 SQL Server
源代码网推荐  rda.Push(
源代码网推荐   "DimEmployee",
源代码网推荐  "Provider=sqloledb;server=MySqlServer;database=AdventureWorks;uid=sa;pwd=;");
源代码网推荐  
源代码网推荐  // 提交 SQL 语句在 SQL Server 上执行
源代码网推荐  rda.SubmitSql(
源代码网推荐   "CREATE TABLE MyRemoteTable (colA int)",
源代码网推荐   "Provider=sqloledb;server=MySqlServer;database=AdventureWorks;uid=sa;pwd=;");
源代码网推荐  
源代码网推荐  7. 使用 SqlCeResultSet
源代码网推荐  // 使用 SqlCeResultSet
源代码网推荐  // 创建 SQL Server Mobile 数据库连接
源代码网推荐  SqlCeConnection conn = new SqlCeConnection("Data Source=Northwind.sdf");
源代码网推荐  
源代码网推荐  // 创建并配置 SqlCeCommand 对象
源代码网推荐  SqlCeCommand cmd = conn.CreateCommand();
源代码网推荐  cmd.CommandText = "SELECT * FROM Orders";
源代码网推荐  
源代码网推荐  // 创建 SqlCeResultSet 对象,并配置为可滚动、可更新、检测数据源更改
源代码网推荐  ResultSetOptions options = ResultSetOptions.Scrollable |
源代码网推荐   ResultSetOptions.Sensitive |
源代码网推荐   ResultSetOptions.Updatable;
源代码网推荐  SqlCeResultSet resultSet = cmd.ExecuteResultSet(options);
源代码网推荐  
源代码网推荐  // 创建 ResultSetView 对象,配置为只显示序号为 1,3,5,8 的列
源代码网推荐  ResultSetView resultSetView = resultSet.ResultSetView;
源代码网推荐  int[] ordinals = new int[] { 1,3,5,8};
源代码网推荐  resultSetView.Ordinals = ordinals;
源代码网推荐  
源代码网推荐  // 将 ResultSetView 绑定到 DataGrid 控件
源代码网推荐  this.dataGrid.DataSource = resultSetView;
源代码网推荐  
源代码网推荐  8. 处理 SqlCeException
源代码网推荐  // 处理 SqlCeException
源代码网推荐  public static void ShowErrors(SqlCeException e)
源代码网推荐  {
源代码网推荐   SqlCeErrorCollection errorCollection = e.Errors;
源代码网推荐  
源代码网推荐   StringBuilder bld = new StringBuilder();
源代码网推荐   Exception inner = e.InnerException;
源代码网推荐  
源代码网推荐   foreach (SqlCeError err in errs)
源代码网推荐   {
源代码网推荐   // 标识错误类型的 HRESULT 值,这些错误不是 SQL Server CE 固有的
源代码网推荐   bld.Append(" Error Code: ").Append(err.HResult.ToString("X"));
源代码网推荐   // 对错误进行描述的文本
源代码网推荐   bld.Append(" Message: ").Append(err.Message);
源代码网推荐   // 获取 SqlCeError 的本机错误号
源代码网推荐   bld.Append(" Minor Err.: ").Append(err.NativeError);
源代码网推荐   // 生成错误的提供程序的名称
源代码网推荐   bld.Append(" Source: ").Append(err.Source);
源代码网推荐  
源代码网推荐   // 遍历前三个错误参数。SQL Server CE 使用错误参数来提供有关错误的其他详细信息。
源代码网推荐   foreach (int numPara in err.NumericErrorParameters)
源代码网推荐   {
源代码网推荐   // 虽然错误可能存在参数,但并非发生的所有错误都返回参数。
源代码网推荐   // 如果发生某个错误时没有返回任何参数,则该数组的值为 0。
源代码网推荐   if (numPara != 0)
源代码网推荐   {
源代码网推荐   bld.Append(" Num. Par.: ").Append(numPara);
源代码网推荐   }
源代码网推荐   }
源代码网推荐  
源代码网推荐   // 遍历最后三个错误参数。SQL Server CE 使用错误参数来提供有关错误的其他详细信息。
源代码网推荐   foreach (string errPara in err.ErrorParameters)
源代码网推荐   {
源代码网推荐   // 虽然错误可能存在参数,但并非发生的所有错误都返回参数。
源代码网推荐   // 如果发生某个错误时没有返回任何参数,则该数组的值将为空字符串。
源代码网推荐   if (errPara != String.Empty)
源代码网推荐   {
源代码网推荐   bld.Append(" Err. Par.: ").Append(errPara);
源代码网推荐   }
源代码网推荐   }
源代码网推荐  }
源代码网推荐  
源代码网推荐   MessageBox.Show(bld.ToString());
源代码网推荐  }
源代码网推荐  
源代码网推荐  参考:
源代码网推荐  SQL Server Mobile 2005 联机丛书
源代码网推荐  MSDN Library
源代码网推荐  
源代码网推荐  http://www.cnblogs.com/upto/archive/2006/08/22/sqlservermobilecode.html
源代码网推荐  
源代码网推荐  
源代码网推荐  
源代码网推荐    做人要厚道,请注明转自酷网动力(www.ASPCOOL.COM)。
源代码网推荐


源代码网供稿.
网友评论 (0)
会员中心
网络编程
本站推荐
网络编程之精华