用于从ASP.NET更新表的动态SQL [英] Dynamic SQL for updating a table from ASP .NET

查看:77
本文介绍了用于从ASP.NET更新表的动态SQL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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.

因此,我需要构建一个框架,以允许更新SQL数据库中的通用表.我见过的大多数ORM都要求在编译时就知道该模式,所以我不能使用它们.最好的答案似乎是动态构建SQL查询字符串,并使用reg表达式来确保有效输入并防止SQL注入.有更好的方法吗?

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?

推荐答案

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

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


(来源: scottgu.com )


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

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

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

这篇关于用于从ASP.NET更新表的动态SQL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆