Author |
Topic |
rsegecin
Yak Posting Veteran
82 Posts |
Posted - 2010-01-09 : 02:34:34
|
Hello I was wondering if I could give names to the tables that are returned in the T-SQL result in order to access them with .NET through their name.Per example the table that returns the states of America must call States:“Select * from states” << name of the result table should call “States”And I could access the tables in the query’s result like that:dataSet.Tables["States"];Thank you very much and happy new year =D.Ideas are bullet proof.V for Vendetta.Fell free to correct me if I misspelled something or a "better way to say it". |
|
sunitabeck
Master Smack Fu Yak Hacker
5155 Posts |
Posted - 2010-01-09 : 16:22:32
|
You can name your data table when creating the table or when filling the dataset. Here is an example with code and explanation. http://support.microsoft.com/kb/307587 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
rsegecin
Yak Posting Veteran
82 Posts |
Posted - 2010-01-09 : 23:32:36
|
quote: Originally posted by sunitabeck You can name your data table when creating the table or when filling the dataset. Here is an example with code and explanation. http://support.microsoft.com/kb/307587
Thank you the quick reply guys.Sunitabeck I know that I can name the datatable with .Net but what I really wanted is to return the table already named from the SQL procedure and then refer the table through her name in the C# code. In the moment right before I return each table from the procedure I'm giving their respective names through another Select query to warn what the next table is called. Per example:Select 'userTable'Select * from usersSelect 'tastesTable'Select * from tastesThis is an example very simple example to what I've to deal. My procedure would be returning around 7 different tables which not all of them might be returned given different circumstances of input values. So distinguishing them one from another is quite annoying that's why I would like to return the tables with their names already setted.Ideas are bullet proof.V for Vendetta.Fell free to correct me if I misspelled something or a "better way to say it". |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-01-10 : 00:58:04
|
quote: Originally posted by tkizer I don't understand why from your application code that you don't already know the table name. I've never seen a requirement in application code like you are asking. You should rethink your design and follow the link that sunitabeck posted.Tara KizerMicrosoft MVP for Windows Server System - SQL Serverhttp://weblogs.sqlteam.com/tarad/Subscribe to my blog"Let's begin with the premise that everything you've done up until this point is wrong."
Seems like what OP is asking is a way to distinguishing different resultsets obtained in application code. |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
rsegecin
Yak Posting Veteran
82 Posts |
Posted - 2010-01-10 : 13:46:05
|
Tara kiser I know that I can name my .NET datatable and how to do it as demonstrated in the link you posted which is referenced the lines in question right below, but what I wanted is that the table came already named from the database so I can access them through their name straight ahead like also showed below. Here you are naming the dataset as “Pubs” and datatable as “Authors”DataSet dsPubs = new DataSet("Pubs");daAuthors.FillSchema(dsPubs,SchemaType.Source, "Authors");daAuthors.Fill(dsPubs,"Authors");*************SqlDataAdapter sqlDataAdapter = new SqlDataAdapter();DataSet dataSet = new DataSet();sqlDataAdapter.Fill(dataSet);dataSet.Tables["Authors"]The name of the tables that are returned from the query are named as ‘Table’, ‘Table1’, ‘Table2’, etc… |
|
|
sunitabeck
Master Smack Fu Yak Hacker
5155 Posts |
Posted - 2010-01-10 : 20:21:03
|
rsegecin, Table, Table1, Table2 etc. is the default mapping that .Net uses to name the record sets. There is no mechanism that I know of within SQL that will allow you to specify a name for a record set and let that name be passed into SQL adapter. However, you can change the mapping as shown on this link: http://msdn.microsoft.com/en-us/library/ms810286.aspx . However, here again, you are doing the mapping in ADO.Net, not in SQL. |
|
|
rsegecin
Yak Posting Veteran
82 Posts |
Posted - 2010-01-10 : 21:29:45
|
Thank you sunitabeck and everybody who helped to enlighten me this problem.Ideas are bullet proof.V for Vendetta.Fell free to correct me if I misspelled something or a "better way to say it". |
|
|
joyasmith
Starting Member
1 Post |
Posted - 2010-02-04 : 05:56:19
|
Well....If you have problem with SQl query ....Study the SQL query concept and try to find out the exact syntax or the command of the query ..which is match with the same problem. if you want to return your name as privious session then clear your values regardindg your database and apply a suitable query.You can do mapping of your tables and apply the query over there....!!--------------------------------------------------------------------- |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-02-04 : 05:59:25
|
quote: Originally posted by joyasmith Well....By using SQL query you can easily solve your problem.Study the SQL query concept and try to find out the exact syntax ..which is match with the same problem. if you want to return your name as privious session then put your values in database and then apply a suitable query.do mapping of your tables and clear and apply the commands over there....!!---------------------------------------------------------------------
what? sorry i didnt get what you're suggesting |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|