Click here to Skip to main content
15,895,777 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi..


Iam facing a problem in retrieving the data from the database table... my question is i have one table in my database i would like to retrieve the all the data in my table except DbId how can i get this can any one help..


Thank's in Advance
Mishrutha
Posted

1 solution

You can't do the equivilent of "SELECT * EXCEPT DbId FROM myTable" - there is no mechanism in Sql for that.

The good practice way to do it is to name all the columns you do wish to retrieve, in the order you want them:
C#
SELECT Column1, Column3, Column2 FROM myTable
The reduces waste in the transfer, as it doesn't get columns you aren't interested in, and specifies the order if you use a numeric index when you access the retrieved data.

You could do it by creating a temporary table, copying the whole table into it, and then dropping the DbId column from the temporary table before returning the whole of that, but t would be incredibly inefficient!
SQL
SELECT * INTO #Temp FROM myTable
ALTER TABLE #Temp DROP COLUMN DbId
SELECT * FROM #Temp
DROP TABLE #Temp
 
Share this answer
 
Comments
Divyay208 26-May-12 1:36am    
Here my table is dynamically created...so i don't no the columns names, in my project client creates the table from front end dynamically
OriginalGriff 26-May-12 3:05am    
Then either he decides which columns to retrieve, or you retrieve them all.
Divyay208 5-Jun-12 1:28am    
Client will decide i mean by clicking on display button the table will be displayed in gridview with out Id's

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