将表名作为参数传递给c#中的存储过程 [英] Passing Table Name as parameter in stored procedure in c#

查看:80
本文介绍了将表名作为参数传递给c#中的存储过程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在处理一个项目,该项目需要使表名动态,这意味着我想从前端将表名作为参数传递给我的存储过程。所以我可以用任何相同的桌面结构来传达任何桌子....





在此先感谢........ ..





请帮助....

I am working on a project and that project need to make table name dynamic, means i want to pass table name as a parameter in my stored procedure from front end. So that i can communicate any table with same table structure....


Thanks in advance..........


pls help....

推荐答案

你可以使用动态查询方法。您实际上将查询构建为字符串并在过程中执行它,因此您可以使用表名作为参数。请看这里:在存储过程中构建动态SQL [< a href =http://www.codeproject.com/Articles/20815/Building-Dynamic-SQL-In-a-Stored-Proceduretarget =_ blanktitle =New Window> ^ ] 。但这样做很少明智。你最终会得到一个不可持续的应用程序。您最好将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.


这篇关于将表名作为参数传递给c#中的存储过程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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