使用Oledb传参数的悲剧,update返回永远是0条记录
2010-03-04 16:25
399 查看
首先我承认.基础不牢靠.
/// <summary>
/// 设置系统设置
/// </summary>
/// <param name="key">键</param>
/// <<param name="val">值得</param>
/// <returns></returns>
public int SetSystemConfig(string key, string val)
{
DbParameter[] parm = {
DbHelper.MakeInParam("@val",(DbType)OleDbType.VarChar,50,val)
,DbHelper.MakeInParam("@key",(DbType)OleDbType.VarChar,50,key)
};
//OleDbConnection conn= new OleDbConnection(DbHelper.ConnectionString);
//conn.Open();
int result=0;
// OleDbCommand cmd = conn.CreateCommand();
string sql = "update [systemConfig] set [sysval]='"+ val +"' where [syskey]='"+ key +"'";
// cmd.CommandText = sql;
result = DbHelper.ExecuteNonQuery( CommandType.Text, @"update [systemConfig] set [sysval]=@val where syskey=@key", parm);
// result = cmd.ExecuteNonQuery();
// conn.Close();
return result;
}
就是上面的那段传参数的.参数传入的位置必须和sql语句中船舷的先后顺序一致..
在此之前,我臆想了我的操作系统与是window7 x64的原因?还是office2007的原因?或者access文件是2006年创建的?其实都不是...
/// <summary>
/// 设置系统设置
/// </summary>
/// <param name="key">键</param>
/// <<param name="val">值得</param>
/// <returns></returns>
public int SetSystemConfig(string key, string val)
{
DbParameter[] parm = {
DbHelper.MakeInParam("@val",(DbType)OleDbType.VarChar,50,val)
,DbHelper.MakeInParam("@key",(DbType)OleDbType.VarChar,50,key)
};
//OleDbConnection conn= new OleDbConnection(DbHelper.ConnectionString);
//conn.Open();
int result=0;
// OleDbCommand cmd = conn.CreateCommand();
string sql = "update [systemConfig] set [sysval]='"+ val +"' where [syskey]='"+ key +"'";
// cmd.CommandText = sql;
result = DbHelper.ExecuteNonQuery( CommandType.Text, @"update [systemConfig] set [sysval]=@val where syskey=@key", parm);
// result = cmd.ExecuteNonQuery();
// conn.Close();
return result;
}
就是上面的那段传参数的.参数传入的位置必须和sql语句中船舷的先后顺序一致..
在此之前,我臆想了我的操作系统与是window7 x64的原因?还是office2007的原因?或者access文件是2006年创建的?其实都不是...
相关文章推荐
- 一句Update语句返回响应0条记录的思考
- OleDBConnection连接Viusal Foxpro表,OleDbCommand在使用Update语句时不可使用参数。
- OleDBConnection连接SQL Server表时,OleDbCommand在使用Update语句时,使用参数出错
- C#使用OleDB操作ACCESS插入数据时提示:至少一个参数没有被指定值。
- c/c++使用指针做函数返回值和指针作函数参数问题
- 使用SqlDataSource新增记录并返回自增ID
- struts中使用json返回参数
- SqlCommand对象的返回参数使用
- OleDbParameter参数的使用
- 使用 OUTPUT 参数返回数据
- .NET中使用ORACLE函数和过程并输出参数(3)使用游标返回列表
- C函数调用-不使用函数返回值,而用参数实现输入/输出的4种模式
- 记录:mysql中的case when|on duplicate key update|重复插入返回主键的用法
- C#中如何使用VC++创建的dll动态链接库的返回参数
- 利用Uri获取返回的参数即getQueryParameter()方法的使用
- 利用dubbo的Filter记录入参、出参及规范返回参数
- C#使用ExecuteReader返回DataReader既有查询结果集又有输出参数和返回值的使用注意事项
- 解决Java程序使用MySQL时返回参数为乱码的示例教程
- rsync参数使用记录
- 【详解】【记录】on duplicate key update简单使用