Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > dataset table name

Reply
Thread Tools

dataset table name

 
 
Antonio
Guest
Posts: n/a
 
      05-26-2006
hi i working whit ado.net2.0 have fill 3 data table to my dataset using
this code

Dim qry1 As String = "SELECT * FROM Employees;SELECT * FROM
Customers;SELECT * FROM Orders"
Dim da1 As New Data.SqlClient.SqlDataAdapter(qry1, cn)
da1.Fill(ds)
my question is :
can i set name of my dataset's table? now i recive table, table1,
table2

Regard

Antonio F.

 
Reply With Quote
 
 
 
 
Rob Meade
Guest
Posts: n/a
 
      05-26-2006
"Antonio" wrote ..

> hi i working whit ado.net2.0 have fill 3 data table to my dataset using
> this code
>
> Dim qry1 As String = "SELECT * FROM Employees;SELECT * FROM
> Customers;SELECT * FROM Orders"
> Dim da1 As New Data.SqlClient.SqlDataAdapter(qry1, cn)
> da1.Fill(ds)
> my question is :
> can i set name of my dataset's table? now i recive table, table1,
> table2


Hi Antonio,

I'm sure someone else will have a better answer, but I've managed to set the
names before, but based on a hard coded solution, rather than dynamically
from the SQL statement, ie...

Something like (and forgive me if this isn't 100% syntactically correct -
its been a while) -

DataSet.DataTable(0).Name = "Fred"
DataSet.DataTable(1).Name = "Barney"

But this would of course assume that you would always populate the dataset
in the same order etc..

Sorry if this isn't a whole lot of help.

Regards

Rob


 
Reply With Quote
 
 
 
 
Kuldeep
Guest
Posts: n/a
 
      05-26-2006
Hello Antonio,

While retrieving data from the dataset,
cant we try giving
objDs.Tables[0].Rows[0]["column_name"].ToString().Trim();

objDs.Tables[0].Rows[1]["column_name"].ToString().Trim();

objDs.Tables[0].Rows[2]["column_name"].ToString().Trim();

where in 0,1,2 would represent 3 different tables of the same dataset objDs

Hope this would help you!

Regards
Kuldeep

"Antonio" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) ups.com...
> hi i working whit ado.net2.0 have fill 3 data table to my dataset using
> this code
>
> Dim qry1 As String = "SELECT * FROM Employees;SELECT * FROM
> Customers;SELECT * FROM Orders"
> Dim da1 As New Data.SqlClient.SqlDataAdapter(qry1, cn)
> da1.Fill(ds)
> my question is :
> can i set name of my dataset's table? now i recive table, table1,
> table2
>
> Regard
>
> Antonio F.
>



 
Reply With Quote
 
Mark Newmister
Guest
Posts: n/a
 
      05-26-2006
....or you could use table mappings:

myDataAdapter.TableMappings.Add("Table1", "Orders");
myDataAdapter.TableMappings.Add("Table2", "OrderDetails");
myDataAdapter.Fill(myDataSet);

"Antonio" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) ups.com...
> hi i working whit ado.net2.0 have fill 3 data table to my dataset using
> this code
>
> Dim qry1 As String = "SELECT * FROM Employees;SELECT * FROM
> Customers;SELECT * FROM Orders"
> Dim da1 As New Data.SqlClient.SqlDataAdapter(qry1, cn)
> da1.Fill(ds)
> my question is :
> can i set name of my dataset's table? now i recive table, table1,
> table2
>
> Regard
>
> Antonio F.
>



 
Reply With Quote
 
embuhrow embuhrow is offline
Junior Member
Join Date: Jul 2008
Posts: 1
 
      07-03-2008
For those looking to just rename the tables in a DataSet, I found that the easiest way to go about doing this is the following.

string[] tables = { "myTable1", "myTable2", "myTable3" };
DataSet ds = new DataSet
string sqlStatement = "SELECT * FROM Table1; SELECT * FROM Table2; SELECT * FROM Table3";
SqlDataAdapter da = new SqlDataAdapter(sqlStatement, connection);
da.Fill(ds);

for (int index = 0; index < ds.Tables.Count; index++)
{
ds.Tables[index].TableName = tables[index];
}
 
Reply With Quote
 
 
 
Reply

Thread Tools

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
How to create DataSet schema with Parent table containing child table donet programmer ASP .Net 1 12-05-2006 03:18 AM
copying a datatable content from an untyped dataset into a table which is inside a typed dataset Nedu N ASP .Net 2 10-31-2003 01:05 PM
Ccopying a datatable content from an untyped dataset into a table which is inside a typed dataset Nedu N ASP .Net Datagrid Control 2 10-31-2003 02:43 AM
Ccopying a datatable content from an untyped dataset into a table which is inside a typed dataset Nedu N ASP .Net 1 10-31-2003 02:39 AM



Advertisments