我试图通过MySql / .NEt连接器使用.Net执行INSERT INTO查询.该查询使用参数.这很简单:INSERT INTO post (ID, content, post_url, blogID, title, addedOn, updatedDate, commentsFeedURL, active, viewCount, co...
![](https://oss.womengda.net/imgfile/2310/1ER2M55O340-5Z58.jpg)
我试图通过MySql / .NEt连接器使用.Net执行INSERT INTO查询.该查询使用参数.这很简单:
INSERT INTO post (
ID, content, post_url, blogID, title, addedOn,
updatedDate, commentsFeedURL, active, viewCount,
commentCount, languageID, authorName, postDate,
posRating, negRating, adult)
VALUES(
@ID, @content, @post_url, @blogID, @title, @addedOn,
@updatedDate, @commentsFeedURL, @active, @viewCount,
@commentCount, @languageID, @authorName, @postDate,
@posRating, @negRating, @adult)
当我运行它(所有参数都正确分配)我得到一个错误
“列’post_url’不能为空”
但它不是空的.这是参数post_url中的值
http://abcd.wordpress.com/2007/08/13/%e0%a4%a6%e0%a5%8b-%e0%a4%ae%e0%a4%bf%e0%a4%a8%e0%a4%9f-%e0%a4%95%e0%a4%be-%e0%a4%a7%e0%a5%8d%e0%a4%af%e0%a4%be%e0%a4%a8/
这是我用来将参数分配给SQL Query的代码
cmd.Parameters.AddWithValue("post_url", postOld.URL);
可能是我得到这种行为的原因是什么?
解决方法:
好的伙计,我终于找到了正确的答案.
问题很简单,在MySQL查询参数中标有’?’不是’@’.不幸的是,许多查询似乎运行良好(他们不是)使用’@’,所以当遇到麻烦时,人们会发现这一点.
谢谢你的所有答案.我重写了这样的查询:
INSERT INTO post (ID, content, post_url, blogID, title, addedOn, updatedDate, commentsFeedURL, active, viewCount, commentCount, languageID, authorName, postDate, posRating, negRating, adult)" +
" VALUES(?ID, ?content, ?post_url, ?blogID, ?title, ?addedOn, ?updatedDate, ?commentsFeedURL, ?active, ?viewCount, ?commentCount, ?languageID, ?authorName, ?postDate, ?posRating, ?negRating, ?adult)
它起作用了.
本文标题为:c# – MySql表示对于非空的列,Column不能为null! [使用命名参数]
![](/xwassets/images/pre.png)
![](/xwassets/images/next.png)
- WPF使用WrapPanel实现虚拟化效果 2023-07-04
- 详细介绍C# 泛型 2023-03-09
- C#用RabbitMQ实现消息订阅与发布 2023-04-15
- C#多线程中的互斥锁Mutex 2023-05-31
- C# 反射与dynamic最佳组合示例代码 2022-11-10
- C#绘制实时曲线的方法 2023-05-22
- 三十分钟快速掌握C# 6.0知识点 2022-11-02
- Unity利用UGUI制作提示框效果 2023-03-03
- unity shader 较完整光照(含有多光源阴影) 2023-05-05
- WPF InkCanvas绘制矩形和椭圆 2023-01-06