多次查询
我有一个 ADO.NET 问题,确实,我想知道是否可以执行盲查询;这意味着用户在文本框中输入任何内容(应该是 SQL 或 T-SQL 语句),然后当他提交时我想即时执行其输入,我已经看到 ADO.NET 有SELECT 和 INSERT/DELETE/UPDATE 语句的方法不同,所以总而言之,有没有办法只执行一堆语句而不先检查它们的类型? (查询可能包含“;”分隔的查询,所以......)
提前致谢,
Miloud Bel。
I've got a ADO.NET question, Indeed, I'd like to know if it's possible to do blind query execution; which means the user enters anything in a text box (well it's supposed to be SQL or T-SQL statement(s)), then when he submits I want to execute its input on the fly, I've seen that ADO.NET has different methods for SELECT and INSERT/DELETE/UPDATE statements, so to conclude, is there a way to just execute a bunch of statements without checking their kind first ? (the query could contain ";" separated queries so...)
Thanks in advance,
Miloud Bel.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您的数据库支持多个语句,您可以使用
;
将它们分开并一次性执行:sqlCommand.ExecuteNonQuery();
。当然,如果您在同一查询中混合使用 SELECT、UPDATE、DELETE,则获取结果可能会很混乱。您还可以检查此示例。If your database supports multiple statements you could separate them with
;
and execute in one go:sqlCommand.ExecuteNonQuery();
. Of course fetching the results could be messy if you mix SELECT, UPDATE, DELETE in the same query. You may also check this sample.