用于从 ASP .NET 更新表的动态 SQL

发布于 2024-07-21 06:50:55 字数 264 浏览 3 评论 0 原文

我有一个 ASP.NET 3.5 应用程序,我希望允许用户选择一个表并允许对该表进行 CRUD 操作。 用户将被限制只能编辑多个表,但是只有在部署之后才能知道这些表甚至数据库; web.config 将设置连接和表。

因此,我需要构建一个框架,允许更新 SQL 数据库中的通用表。 我见过的大多数 ORM 都要求在编译时了解架构,因此我无法使用它们。 最好的答案似乎是动态构建 SQL 查询字符串并使用 reg 表达式来确保有效输入并防止 SQL 注入。 有没有更好的办法?

I have an ASP.NET 3.5 application that I want to allow the user to select a table and allow CRUD operations on that table. The user will be restricted to a number of tables to edit however the tables and even database won't be known until after deployment; the web.config will setup the connection and tables.

So I need to build a framework that will allow a generic table in a SQL database to be updated. Most of the ORMs I've seen require the schema to be known at compile time so I cannot use these. The best answer seems to be build the SQL query strings dynamically and use reg expressions to ensure valid input and protect against SQL injections. Is there a better way?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

蝶…霜飞 2024-07-28 06:50:55

是的。 数据集和数据表对象怎么样? 您可以通过动态 sql 语句填充它们,将它们直接绑定到良好的编辑器网格控件,并且架构和列数据类型检查应该很简单。 在 ORM 和 Linq 之前我们做过什么?!?!

Yes. How about dataset and datatable objects? you can populate these via a dynamic sql statement, bind them directly to a good editor grid control, and the schema and column data type checking should be a snap. What did we ever do before ORM's and Linq?!?!

云醉月微眠 2024-07-28 06:50:55

动态 Linq 库令人难以置信。 您可以将所有内容指定为字符串,除了表名称。

替代文本
(来源:scottgu.com
http://weblogs.asp.net/scottgu/archive/2008/01/07/dynamic-linq-part-1-using-the-linq-dynamic-query-library.aspx

但是,请在此处查找有关如何通过动态映射 DataContext 在运行时选择表的想法:

http://blogs.microsoft.co.il/blogs/bursteg/archive/2007/09/27/25294.aspx

The Dynamic Linq Library is incredible. You can specify everything as a string, except maybe the table names.

alt text
(source: scottgu.com)
http://weblogs.asp.net/scottgu/archive/2008/01/07/dynamic-linq-part-1-using-the-linq-dynamic-query-library.aspx

However, look here for ideas on how to select tables at runtime by dynamically mapping the DataContext:

http://blogs.microsoft.co.il/blogs/bursteg/archive/2007/09/27/25294.aspx

江南烟雨〆相思醉 2024-07-28 06:50:55

您可以使用 JJMasterData 为表中的所有 CRUD 操作动态生成 SQL 脚本。 我们支持 .NET 6 和 .NET Framework 4.8。

https://www.github.com/jjconsulting/JJMasterData

You can use JJMasterData to dynamic generate SQL scripts for all CRUD operations from a table. We support both .NET 6 and .NET Framework 4.8.

https://www.github.com/jjconsulting/JJMasterData

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文