为什么这个result为空?我点上面都是有值的为什么result=0?

qq_32320747 2018-04-17 10:25:06

  public Boolean UpdateData(DataContract.infection.infection entity)
{
int result = 0;
try
{
string sql;
sql = string.Format(@" update {0} set pid=@pid,ipid=@ipid,icd1=@icd1,icd2=@icd2
,icd3=@icd3,填卡日期=@填卡日期,报卡编号=@报卡编号,身份证号=@身份证号,病人姓名=@病人姓名
,报告医生=@报告医生,inXml=@inXml,inXml1=@inXml1,inXml2=@inXml2,inXml3=@inXml3
,inXml4=@inXml4,RecordUser=@RecordUser,RecordTime=@RecordTime,is上传=@is上传,上传人=@上传人
,上传时间=getdate()
where ID=@ID", TableName);
sql += string.Format(@" select @id={0}", entity.ID);
SqlParameter[] param = new SqlParameter[]{
SqlHelper.MakeOutParam("@ID",SqlDbType.Int,entity.ID),
SqlHelper.MakeInParam("@pid",SqlDbType.Int,entity.pid),
SqlHelper.MakeInParam("@ipid",SqlDbType.Int,entity.ipid),
SqlHelper.MakeInParam("@icd1",SqlDbType.VarChar,entity.icd1),
SqlHelper.MakeInParam("@icd2",SqlDbType.VarChar,entity.icd2),
SqlHelper.MakeInParam("@icd3",SqlDbType.VarChar,entity.icd3),
SqlHelper.MakeInParam("@填卡日期",SqlDbType.DateTime,entity.填卡日期),
SqlHelper.MakeInParam("@报卡编号",SqlDbType.VarChar,entity.报卡编号),
SqlHelper.MakeInParam("@身份证号",SqlDbType.VarChar,entity.身份证号),
SqlHelper.MakeInParam("@病人姓名",SqlDbType.VarChar,entity.病人姓名),
SqlHelper.MakeInParam("@报告医生",SqlDbType.VarChar,entity.报告医生),
SqlHelper.MakeInParam("@inXml",SqlDbType.VarChar,entity.inXml),
SqlHelper.MakeInParam("@inXml1",SqlDbType.VarChar,entity.inXml1),
SqlHelper.MakeInParam("@inXml2",SqlDbType.VarChar,entity.inXml2),
SqlHelper.MakeInParam("@inXml3",SqlDbType.VarChar,entity.inXml3),
SqlHelper.MakeInParam("@inXml4",SqlDbType.VarChar,entity.inXml4),
SqlHelper.MakeInParam("@RecordUser",SqlDbType.VarChar,ThisConn.userlistname),
SqlHelper.MakeInParam("@RecordTime",SqlDbType.DateTime,entity.RecordTime),
SqlHelper.MakeInParam("@is上传",SqlDbType.Int,entity.is上传),
SqlHelper.MakeInParam("@上传人",SqlDbType.VarChar,ThisConn.userlistname)
};
result = SqlHelper.ExecuteNonQuery(ThisConn.sCono, CommandType.Text, sql, param);
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
return result > 0 ? true : false;
}
...全文
1249 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
zyy1111111 2018-04-20
  • 打赏
  • 举报
回复
     select @ID=Scope_identity()
                         end", TableName);

                SqlParameter[] param = new SqlParameter[]{
                            SqlHelper.MakeOutParam("@ID",SqlDbType.Int,entity.ID),
这个就不要了,
xuzuning 2018-04-18
  • 打赏
  • 举报
回复
13行的 sql += string.Format(@" select @id={0}", entity.ID); 是蛇足 1、其目的是相同时执行两条 SQL 指令,但与前一条间缺少行结束符(;),导致整个 SQL 指令语法错误 2、@id 表示一个用户自定义变量,但并未看到你在何处定义了他,显然是 SQL 指令语法错 SQL 指令都错了,你还能指望他返回什么?
李敢敢 2018-04-18
  • 打赏
  • 举报
回复
为什么还要加一个查询。。。最后也只是返回成功失败啊
wang_peng_yl 2018-04-18
  • 打赏
  • 举报
回复
你脚本里是两个命令,ExecuteNonQuery肯定不行, 用 SqlDataAdapter 去执行,  string.Format(@" select @id={0}", entity.ID);改成 string.Format(@" select {0}", entity.ID); 否则你还是什么都反不回来
exception92 2018-04-17
  • 打赏
  • 举报
回复
http://www.cnblogs.com/alexis/archive/2010/11/06/1870519.html 调试你的代码吧,看ExecuteNonQuery方法执行之后返回的是什么。 ”上面都是有值“这种疑问要从学会调试代码开始排除问题。
  • 打赏
  • 举报
回复
不明白你update要把id再select出来干嘛,一般add时需要select出最后的自增主键
  • 打赏
  • 举报
回复
ExecuteNonQuery 返回受影响行数 ExecuteScale返回第一行第一列

110,561

社区成员

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

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

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