Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我在将此字符串写入我的 SQL 200 数据库表时遇到问题:
从字符串“”到类型“整数”的转换无效。
如何确保我的 vb.net 应用程序将上面的字符串完全按照它的出现写入表中的字段?
出于多种原因,我建议使用 SqlCommand 和 SqlParameters,而不是原始 SQL 字符串。要在 SQL 中转义字符,默认情况下,我相信您只需将它们加倍(例如,' 变为 '')。
我相信转义字符的唯一规则是:
_
%
因此,您应该可以通过首先对字符串进行 3 次搜索和替换来轻松插入您喜欢的任何字符串 - 替换'为''、替换_为\_和替换%为\%
'
''
\_
\%