SqlCeCommand的Parameters为何无效了?

hcaihao 2006-12-16 04:01:32
SqlCeCommand updateCmd = new SqlCeCommand("update [Setting] set 启动窗体=@启动窗体,城市=@城市,更新网址=@更新网址", conn);
//添加参数
updateCmd.Parameters.Add(new SqlCeParameter("@启动窗体", SqlDbType.NVarChar, 50));
updateCmd.Parameters.Add(new SqlCeParameter("@城市", SqlDbType.NVarChar, 50));
updateCmd.Parameters.Add(new SqlCeParameter("@更新网址", SqlDbType.NText));
//设置参数
updateCmd.Parameters["@启动窗体"].Value = setting.启动窗体;
updateCmd.Parameters["@城市"].Value = setting.城市;
updateCmd.Parameters["@更新网址"].Value = setting.更新网址;
//执行命令
updateCmd.ExecuteNonQuery();

运行时发现updateCmd.CommandText值仍旧是"update [Setting] set 启动窗体=@启动窗体,城市=@城市,更新网址=@更新网址"

也就是说三个参数没有起作用,为何,这个在Asp.net中是可以的,为何到了Windows Mobile中就海了???
...全文
243 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
cinray 2006-12-27
  • 打赏
  • 举报
回复
Ding
kason_j 2006-12-27
  • 打赏
  • 举报
回复
友情幫頂
hcaihao 2006-12-27
  • 打赏
  • 举报
回复
可以用的,Net支持Unicode,而且这段代码在asp.net中是没问题的。现在改成英文一样不行
yaopeng117 2006-12-26
  • 打赏
  • 举报
回复
updateCmd.Parameters.Add(new SqlCeParameter("@启动窗体", SqlDbType.NVarChar, 50));

参数名能用中文的吗?
hcaihao 2006-12-26
  • 打赏
  • 举报
回复
楼上的办法可行?
sprider 2006-12-21
  • 打赏
  • 举报
回复
先该参数.
后Parameters.Add
hcaihao 2006-12-21
  • 打赏
  • 举报
回复
不是中文问题,CE是windows mobile平台的SDK提供的
greatbag 2006-12-16
  • 打赏
  • 举报
回复
楼主的中式程序写得太好了
估计是中文引起的
zhaochong12 2006-12-16
  • 打赏
  • 举报
回复
http://msdn2.microsoft.com/zh-cn/library/system.data.sqlserverce.sqlcecommand(VS.80).aspx
zhaochong12 2006-12-16
  • 打赏
  • 举报
回复
--#...
liujia_0421 2006-12-16
  • 打赏
  • 举报
回复
建议换成英文的试试...
liuchao305 2006-12-16
  • 打赏
  • 举报
回复
SqlCeParameter 怎么比SqlParameter多了个ce能说一下么?还真不知道是什么?
windows ce的开发int startTickCount = Environment.TickCount; // 创建源 SQL Server 数据库连接对象 string srcConnString = "Data Source=(local);Initial Catalog=Northwind;User Id=sa;Password=123;"; SqlConnection srcConnection = new SqlConnection(srcConnString); // 创建目标 SQL Server Compact Edition 数据库连接对象 string destConnString = @"Data Source=Northwind.sdf"; SqlCeConnection destConnection = new SqlCeConnection(destConnString); VerifyDatabaseExists(destConnString); srcConnection.Open(); destConnection.Open(); // 复制数据 CopyTable(srcConnection, destConnection, "SELECT * FROM Products", "Products"); CopyTable(srcConnection, destConnection, "SELECT * FROM Employees", "Employees"); srcConnection.Close(); destConnection.Close(); MessageBox.Show((Environment.TickCount - startTickCount).ToString()); } /// /// 将源数据库表的数据复制到 SQL Server Compact Edition 数据库的表中。 /// /// 源数据库连接接对象。 /// 目标 SQL Server Compact Edition 数据库连接对象。 /// 源数据的查询语句。 /// 目标数据库表名称。 /// 本方法假设目标 SQL Server Compact Edition 数据库的表已经存在。 public static void CopyTable( IDbConnection srcConnection, SqlCeConnection destConnection, string queryString, string destTableName) { IDbCommand srcCommand = srcConnection.CreateCommand(); srcCommand.CommandText = queryString; SqlCeCommand destCommand = destConnection.CreateCommand(); destCommand.CommandType = CommandType.TableDirect; //基于表的访问,性能更好 destCommand.CommandText = destTableName; try { IDataReader srcReader = srcCommand.ExecuteReader(); SqlCeResultSet resultSet = destCommand.ExecuteResultSet( ResultSetOptions.Sensitive | //检测对数据源所做的更改 ResultSetOptions.Scrollable | //可以向前或向后滚动 ResultSetOptions.Updatable); //允许更新数据 object[] values; SqlCeUpdatableRecord record; while (srcReader.Read()) { // 从源数据库表读取记录 values = new object[srcReader.FieldCount]; srcReader.GetValues(values); // 把记录写入到目标数据库表 record = resultSet.CreateRecord(); record.SetValues(values); resultSet.Insert(record); } srcReader.Close(); resultSet.Close(); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.ToString()); } } public static void VerifyDatabaseExists(string connectionString) { using (SqlCeConnection connection = new SqlCeConnection(connectionString)) { if (!File.Exists(connection.Database)) { using (SqlCeEngine engine = new SqlCeEngine(connection.ConnectionString)) { engine.CreateDatabase(); string[] commands = Properties.Resources.DbSchema.Split(';'); SqlCeCommand command = new SqlCeCommand(); command.Connection = connection; connection.Open(); string query; for (int i = 0; i < commands.Length; i++) { query = commands[i].Trim(); if (!string.IsNullOrEmpty(query)) { command.CommandText = query; command.ExecuteNonQuery(); } } } } }

110,545

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

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