PC Review


Reply
Thread Tools Rate Thread

DataSet data table name

 
 
Ron Harter
Guest
Posts: n/a
 
      1st Jul 2009

I have setup for select statements to retrieve data from 4 tables. When all
is said and done and I look for certain tables in the returned DataSet I am
unable to locate the table. When I dig into the DataSet I discovered the 4
tables had names of table, table1, table2, and table3.

I expected VS2008 sp1 and SQL Server 2008 developers edition to return the
proper table name from the data base. Has anyone seen this problem? Is it a
problem? I am enclosing the code snippet

DataSet ds = new DataSet();
DbProviderFactory dbProviderFactory =
DbProviderFactories.GetFactory("System.Data.SqlClient");

using (DbConnection conn = dbProviderFactory.CreateConnection())
{
string s =
ConfigurationManager.ConnectionStrings["Events"].ConnectionString;
conn.ConnectionString = s;
conn.Open();

DbCommand cmd = conn.CreateCommand();
cmd.CommandText = "Select * from FixedHolidays Select * from
FloatingHolidays Select * from LostBoats Select * from Events";

DbDataAdapter dbAdapter = dbProviderFactory.CreateDataAdapter();
dbAdapter.SelectCommand = cmd;
dbAdapter.Fill(ds);

foreach (DataTable t in ds.Tables)
{
Console.WriteLine("Table " + t.TableName + " is in DataSet");
}
}


-----
Ron Harter | Tongue, Tied and Twisted
(E-Mail Removed) | Just An Earthbound Misfit ... I
| Pink Floyd

 
Reply With Quote
 
 
 
 
Cor Ligthert[MVP]
Guest
Posts: n/a
 
      1st Jul 2009
Hi Ron,

Have a look at mappings

http://msdn.microsoft.com/en-us/library/ks92fwwh.aspx

Cor


"Ron Harter" <(E-Mail Removed)> wrote in message
newsE925332-6F4C-4D09-8223-(E-Mail Removed)...
>
> I have setup for select statements to retrieve data from 4 tables. When
> all is said and done and I look for certain tables in the returned DataSet
> I am unable to locate the table. When I dig into the DataSet I discovered
> the 4 tables had names of table, table1, table2, and table3.
>
> I expected VS2008 sp1 and SQL Server 2008 developers edition to return the
> proper table name from the data base. Has anyone seen this problem? Is it
> a problem? I am enclosing the code snippet
>
> DataSet ds = new DataSet();
> DbProviderFactory dbProviderFactory =
> DbProviderFactories.GetFactory("System.Data.SqlClient");
>
> using (DbConnection conn = dbProviderFactory.CreateConnection())
> {
> string s =
> ConfigurationManager.ConnectionStrings["Events"].ConnectionString;
> conn.ConnectionString = s;
> conn.Open();
>
> DbCommand cmd = conn.CreateCommand();
> cmd.CommandText = "Select * from FixedHolidays Select * from
> FloatingHolidays Select * from LostBoats Select * from Events";
>
> DbDataAdapter dbAdapter = dbProviderFactory.CreateDataAdapter();
> dbAdapter.SelectCommand = cmd;
> dbAdapter.Fill(ds);
>
> foreach (DataTable t in ds.Tables)
> {
> Console.WriteLine("Table " + t.TableName + " is in DataSet");
> }
> }
>
>
> -----
> Ron Harter | Tongue, Tied and Twisted
> (E-Mail Removed) | Just An Earthbound Misfit ... I
> | Pink Floyd


 
Reply With Quote
 
sloan
Guest
Posts: n/a
 
      1st Jul 2009

What happens when "Table1" is the result of a join Select

Example:
Select d.DeptID , d.DeptName , e.EmpID , e.LastName, e.FirstName
from
dbo.Dept d join dbo.Employee e on d.DeptID = e.DeptID


???
What should the table name be here?


Aka, you can't just assume a table name.
.............

Have you tried to create a (strong) (or typed) DataSet? And populate it?

PS
http://msdn.microsoft.com/en-us/library/bb748727.aspx


Microsoft.Practices.EnterpriseLibrary.Data.Database.LoadDataSet
provides a string array parameter to name your tables
Public Overridable Sub LoadDataSet ( _
storedProcedureName As String, _
dataSet As DataSet, _
tableNames As String(), _
ParamArray parameterValues As Object() _
)



public virtual void LoadDataSet (
string storedProcedureName,
DataSet dataSet,
string[] tableNames,
params Object[] parameterValues
)



If you have a strong dataset

Lets say my strong dataset is named MyStrongDS, with 2 tables.
Department
Employee

The code (partial code sample) would look like this:


MyStrongDS returnDS = new MyStrongDS();
db.LoadDataSet(dbc, returnDS, new String[] { "Department" ,
Employee" });

Actually, I prefer this (below)
This would avoid accidently giving a bad name via a string.


MyStrongDS returnDS = new MyStrongDS();
db.LoadDataSet(dbc, returnDS, new String[] {
returnDS.Department.TableName, returnDS.Employee.TableName });


If I ever remove or rename a table in MyStrongDataSet, the consequences show
up immediately when I try to build.





"Ron Harter" <(E-Mail Removed)> wrote in message
newsE925332-6F4C-4D09-8223-(E-Mail Removed)...
>
> I have setup for select statements to retrieve data from 4 tables. When
> all is said and done and I look for certain tables in the returned DataSet
> I am unable to locate the table. When I dig into the DataSet I discovered
> the 4 tables had names of table, table1, table2, and table3.
>
> I expected VS2008 sp1 and SQL Server 2008 developers edition to return the
> proper table name from the data base. Has anyone seen this problem? Is it
> a problem? I am enclosing the code snippet
>
> DataSet ds = new DataSet();
> DbProviderFactory dbProviderFactory =
> DbProviderFactories.GetFactory("System.Data.SqlClient");
>
> using (DbConnection conn = dbProviderFactory.CreateConnection())
> {
> string s =
> ConfigurationManager.ConnectionStrings["Events"].ConnectionString;
> conn.ConnectionString = s;
> conn.Open();
>
> DbCommand cmd = conn.CreateCommand();
> cmd.CommandText = "Select * from FixedHolidays Select * from
> FloatingHolidays Select * from LostBoats Select * from Events";
>
> DbDataAdapter dbAdapter = dbProviderFactory.CreateDataAdapter();
> dbAdapter.SelectCommand = cmd;
> dbAdapter.Fill(ds);
>
> foreach (DataTable t in ds.Tables)
> {
> Console.WriteLine("Table " + t.TableName + " is in DataSet");
> }
> }
>
>
> -----
> Ron Harter | Tongue, Tied and Twisted
> (E-Mail Removed) | Just An Earthbound Misfit ... I
> | Pink Floyd



 
Reply With Quote
 
Ron Harter
Guest
Posts: n/a
 
      2nd Jul 2009

Thanks, the mappings worked perfectly.


"Cor Ligthert[MVP]" <(E-Mail Removed)> wrote in message
news:uSgVsMh%(E-Mail Removed)...
> Hi Ron,
>
> Have a look at mappings
>
> http://msdn.microsoft.com/en-us/library/ks92fwwh.aspx
>
> Cor
>
>
> "Ron Harter" <(E-Mail Removed)> wrote in message
> newsE925332-6F4C-4D09-8223-(E-Mail Removed)...
>>
>> I have setup for select statements to retrieve data from 4 tables. When
>> all is said and done and I look for certain tables in the returned
>> DataSet I am unable to locate the table. When I dig into the DataSet I
>> discovered the 4 tables had names of table, table1, table2, and table3.
>>
>> I expected VS2008 sp1 and SQL Server 2008 developers edition to return
>> the proper table name from the data base. Has anyone seen this problem?
>> Is it a problem? I am enclosing the code snippet
>>
>> DataSet ds = new DataSet();
>> DbProviderFactory dbProviderFactory =
>> DbProviderFactories.GetFactory("System.Data.SqlClient");
>>
>> using (DbConnection conn = dbProviderFactory.CreateConnection())
>> {
>> string s =
>> ConfigurationManager.ConnectionStrings["Events"].ConnectionString;
>> conn.ConnectionString = s;
>> conn.Open();
>>
>> DbCommand cmd = conn.CreateCommand();
>> cmd.CommandText = "Select * from FixedHolidays Select * from
>> FloatingHolidays Select * from LostBoats Select * from Events";
>>
>> DbDataAdapter dbAdapter = dbProviderFactory.CreateDataAdapter();
>> dbAdapter.SelectCommand = cmd;
>> dbAdapter.Fill(ds);
>>
>> foreach (DataTable t in ds.Tables)
>> {
>> Console.WriteLine("Table " + t.TableName + " is in DataSet");
>> }
>> }
>>
>>
>> -----
>> Ron Harter | Tongue, Tied and Twisted
>> (E-Mail Removed) | Just An Earthbound Misfit ... I
>> | Pink Floyd

>


--

-----
Ron Harter | Tongue, Tied and Twisted
(E-Mail Removed) | Just An Earthbound Misfit ... I
| Pink Floyd

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Data in table through dataset or bindingsource =?Utf-8?B?RXJpYyBBbGdlcmE=?= Microsoft ADO .NET 8 6th May 2006 03:17 AM
Is there a way to look at the data in a table in a dataset? =?Utf-8?B?QWxwaGE=?= Microsoft C# .NET 1 13th May 2005 09:40 PM
How to update a dataset which data come from two table ad Microsoft ASP .NET 1 18th Mar 2005 02:11 AM
Data from Dataset into new table in SQL John Microsoft ADO .NET 2 11th May 2004 09:46 PM
using Crystal Reports to display data in my dataset correctly (display the data I selected instead of all the data in table) JK Microsoft C# .NET 1 6th Sep 2003 10:10 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:57 AM.