且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

将表名作为参数传递给c#中的存储过程

更新时间:2023-02-12 16:47:41

你可以使用动态查询方法。您实际上将查询构建为字符串并在过程中执行它,因此您可以使用表名作为参数。请看这里:在存储过程中构建动态SQL [ ^ ] 。但这样做很少明智。你最终会得到一个不可持续的应用程序。您***将DAL和BL放在DBMS附近,并在更高级别上解决此需求。
You can use dynamic query approach. You practically build your query as string and execute it inside the procedure, so you can use your table name as parameter. Look here: Building Dynamic SQL In a Stored Procedure[^]. But it rarely wise to do so. You will end up with an unsustainable application. You better put your DAL and BL "near" the DBMS, and solve this need on a higher level.


http://www.daniweb.com/software-development/csharp/threads/370541 / pass-table-name-as-a-parameter-in-stored-procedure-using-c [ ^ ]


将表名作为字符串传递,并在存储过程中在varchar中编写查询语句,最后使用exec方法对该语句执行。
pass table name as a string and in store procedure write a query statement in varchar and finally execute using exec method to that statement.