Click here to Skip to main content
15,891,513 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
SQL
create database test;
create table table1(id bigint,name nvarchar(max));
insert table table1 values(1,'griff');
insert table table1 values(2,'sergey');
insert table table1 values(2,'king');
insert table table1 values(2,'fisher');



and i am expecting
select *From table1

SQL
id name       database
1  griff      test
2  sergey     test
3  king       test
4  fisher     test



how can i Select this.
Thanks ;)
Posted
Updated 6-Mar-14 19:32pm
v2
Comments
SViki 7-Mar-14 1:53am    
I think u are asking that you should mention the database name in the query?
If that is your question you don't need to worry about it.your connection string will take care of it.
King Fisher 7-Mar-14 1:57am    
i wanna select the table records with database name.i want to show in Grid

Use as below
SQL
select  *,db_name() [database] from table1


Thanks,
-RG
 
Share this answer
 
Comments
King Fisher 7-Mar-14 2:44am    
hats off..:)
Ramug10 7-Mar-14 2:47am    
Thanks King....:)
For SQL Server you can create stored procedure with dynamic query:
SQL
--@table = 'test'
CREATE PROCEDURE GetTableData
    @table VARCHAR(30)
AS
BEGIN

DECLARE @sql VARCHAR(300)


SET @sql = 'SELECT *, ' + @table + 'AS TableName FROM ' + @table 
EXEC(@sql)
GO

END


How to: Execute a Stored Procedure that Returns Rows[^]
 
Share this answer
 
v2
http://www.csharptutorial.in/2013/09/CNet-GridView-Example-How-To-Bind-Gridview-in-Asp.net-using-SQLDataSource-at-Design-time.html#.Uxlvcz-SzvA

Hope this will be helpful.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900