首页 / C# / c#-参数化的查询被截断并且参数丢失
c#-参数化的查询被截断并且参数丢失
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了c#-参数化的查询被截断并且参数丢失,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含1465字,纯文字阅读大概需要3分钟。
内容图文
我有一段代码:
command.Parameters.Clear();
command.Parameters.Add(ownerUserIDParam);
command.Parameters.Add(buddyUserIDParam);
command.Parameters.Add(timestampParam);
command.Parameters.Add(new SqlParameter("@GiftID", giftID));
command.Parameters.Add(new SqlParameter("@GiftStatus", (byte)GiftStatusEnum.wait));
command.CommandText = "INSERT INTO SentGefts (OwnerUserID, BuddyUserID, CreateTS, GiftID, Status, AcceptRejectTS, ParentEntityType, ParentEntityID) VALUES (@OwnerUserID, @BuddyUserID, @TS, @GiftID, @GiftStatus, @TS, 0 ,0);";
command.CommandText += "SELECT @@IDENTITY;";
result.GiftInstanceID = long.Parse(command.ExecuteScalar().ToString());
我收到:参数化查询'(@OwnerUserID int,@ BuddyUserID int,@ TS datetime,@ GiftID int,@ Gif’期望使用未提供的参数’@GiftStatus’.
注意:'(@OwnerUserID int,@ BuddyUserID int,@ TS datetime,@ GiftID int,@ Gif’被截断并且正好是64个符号…并且它仅以未完成的参数名称’Gif’结尾(并且例外是也有关此参数).
为什么看不到我的参数?
UPD:
如果我这样添加最后一个参数(@GiftStatus):
command.Parameters.AddWithValue(“ @ GiftStatus”,(byte)GiftStatusEnum.wait);
这样事情就开始起作用.但是我只是无法弄清楚.Add(new SqlParamter());的问题所在;
解决方法:
您需要提供所有参数及其名称.
您最好使用Paramteres.AddWithValue(…).
所以:
Parameters.AddWithValue("@OwnerUserID", ...);
Parameters.AddWithValue("@BuddyUserID", ...);
Parameters.AddWithValue("@TS", ...);
Parameters.AddWithValue("@GiftID", ...);
Parameters.AddWithValue("@GiftStatus", ...);
内容总结
以上是互联网集市为您收集整理的c#-参数化的查询被截断并且参数丢失全部内容,希望文章能够帮你解决c#-参数化的查询被截断并且参数丢失所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。