dataset table name

A

Antonio

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.
 
R

Rob Meade

..
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
 
K

Kuldeep

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
 
M

Mark Newmister

....or you could use table mappings:

myDataAdapter.TableMappings.Add("Table1", "Orders");
myDataAdapter.TableMappings.Add("Table2", "OrderDetails");
myDataAdapter.Fill(myDataSet);
 
Joined
Jul 3, 2008
Messages
1
Reaction score
0
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];
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top