根据用户给出的表名从sql server db表中检索数据 [英] retrieving a data from sql server db table based on tablename given by the user

查看:65
本文介绍了根据用户给出的表名从sql server db表中检索数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好我检索了数据库表名并填充到了combobox中。我在我的应用程序中使用gridview。我想根据用户在combobox中选择的tablename在gridview中显示表。如何做?

Hi I retreived database tablenames and populated into combobox.and i using gridview in my application.i want to display the table in gridview based on the tablename selected by the user which is in combobox.How to do this?

推荐答案

您已经了解了编程以及如何访问数据库。我建议你创建下面的程序并从你的代码中运行这个参数作为用户从combobox中选择



As you already aware of programming and how to access database . I would suggest you to create below procedure and run this from your code with parameter as your user selection from combobox

CREATE PROC [spGetTableData]( @tblname nvarchar(MAX))
 
AS
 
  declare @cmd nvarchar(max)
 
  declare @parameters nvarchar(max)
 
  set @cmd = N'SELECT * FROM @tblname'
 
  set @parameters = '@tblname nvarchar(MAX)'
 
  EXEC sp_executesql @cmd, @parameters, @tblname = @tblname 
 
go





希望这有帮助

--Rahul D。



Hope this helps
--Rahul D.


这篇关于根据用户给出的表名从sql server db表中检索数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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