Click here to Skip to main content
15,886,578 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
Hi to all,
I don't know whether it is possible or not, to display table name in list view control from database.

It goes like this.

I have a tables(several) in Sql Server 2008. sometime i was asked to represent the current status of database in respect to client id (unique attribute), in order to provide this information i have to do query.

To avoid this, i designed a form wherein a user enters client id and results appear in list view with the current status from the database.

Now i m in a fix. I dont know to display the table name in list view. For ex: select [client id], min([invoice month]) as startdate, max([invoice month]) as enddate From tbl_catalogue_Tax_spend_analysis group by [client id].

so my table name is : catalogue_Tax_spend_analysis.

How do i display this name in my listview control.

Please


Thanks in advance.
Posted
Comments
Herman<T>.Instance 26-Aug-11 3:37am    
good question.
Shahan Ayyub 26-Aug-11 8:47am    
Do you have a specific format defined for table name ?
Like:
t_Table1
t_Table2
OR
tbl_Table1
tbl_Table2

etc...
Tinneminy 27-Aug-11 3:43am    
Thanks for the reply.

Thing is i need to display 10 different tables current status of data like minimum and maximum months data on the basis of distinct [client id].
My Table names are:
tbl_Catalogue_Tax_spend_Analysis
tbl_Catalogue_Overall_spend_Analysis
tbl_Catalogue_Air_Activity
tbl_Catalogue_Hotel_Booking
tbl_Catalogue_Car_Booking
tbl_Catalogue_Lost_Hotel
etc...

I want to show the information like eg.,

Catalogue_Tax_spend_Analysis May 2009 July 2011
catalogue_Overall_spend_analysis May 2009 June 2011

1 solution

You have to read the string per character. First find out where FROM is found in your string and then read the character until you find a space or a comma. One more if to check. IF after the from the query starts with a [ you have to find the next ]. Then you have your tablename and can place it in your listview.
 
Share this answer
 
Comments
Tinneminy 27-Aug-11 3:42am    
Thanks for the reply.

Thing is i need to display 10 different tables current status of data like minimum and maximum months data on the basis of distinct [client id].
My Table names are:
tbl_Catalogue_Tax_spend_Analysis
tbl_Catalogue_Overall_spend_Analysis
tbl_Catalogue_Air_Activity
tbl_Catalogue_Hotel_Booking
tbl_Catalogue_Car_Booking
tbl_Catalogue_Lost_Hotel
etc...

I want to show the information like eg.,

Catalogue_Tax_spend_Analysis May 2009 July 2011
catalogue_Overall_spend_analysis May 2009 June 2011


Now as per the solution given by digimanus, how should i do this.i mean i m confuse. Could you explain this with an example.
Herman<T>.Instance 27-Aug-11 15:45pm    
why don't you do int location = query.IndexOf("tbl_");
then you know where the tablename starts

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