I hope you are talking aobur DataTables. Simple name them by some uniqe name. If there is no other way, you can use numbers from 1 to 30 (as jockeyvn proposed), or use the name from sql table (table1, table2,table3 - if they are all different). Or use more sql table names, if there is any dataTable which has two or more sql tables (like: "... FROM Table1, Table2" - name dataTable as :Table1_Table2.
Remember its always good to name dataTables to something that you know what is in it (where it comes from). It easier to work. Thats why I would not recommend you to use numbers only.
Mitja Bonca
Posting Maven
2,561 posts since May 2009
Reputation Points: 642
Solved Threads: 486
Skill Endorsements: 13
Simple. YOu simply add a name in the brackets of the ds.Tables:
DataTable myTable = ds.Tables["table_passenger_details"];
Mitja Bonca
Posting Maven
2,561 posts since May 2009
Reputation Points: 642
Solved Threads: 486
Skill Endorsements: 13
How did your tables loose their names? Cant be?
If you do it right, the names will for sure stay (be there from the time of creation on...
YOu have to do code in C#, (create DataTable as well) and only call a storedProcedure (which only can include SELECT statement, nothing else), and fill in up:
DataSet ds = new DataSet();
public Form1()
{
InitializeComponent();
}
private void GetData()
{
//DO THE SAME FOR EVERY SINLGE DATATABLE, LIKE THIS EXAMPLE:
using (SqlConnection sqlConn = new SqlConnection("connString"))
{
SqlCommand cmd = new SqlCommand();
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "YourProcedureName";
cmd.Connection = sqlConn;
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable table = new DataTable("MyTable1");
ds.Tables.Add(table);
da.Fill(table);
}
}
private void ReadData()
{
DataTable table = ds.Tables["MyTable1"];
foreach (DataRow dr in table.Rows)
{
//code to get each value form dataTable goes here
}
}
If you will do anything different, you will surely look tables, or something else.
Mitja Bonca
Posting Maven
2,561 posts since May 2009
Reputation Points: 642
Solved Threads: 486
Skill Endorsements: 13
Sure, you do not specify the table names. Look into my code, how I did it. I did named the dataTable, so it has a name, your do not have, because you fill dataTables (all togeter) in one stored procedure.
One more thing: the SqlDataAdapter will not look at the physical table names in your database to determine the table names in the ADO.NET DataSet. Sorry, there's really no way to do this automagically.
Why dont you create 3 sepersted stored procedures and use the code I did?
Mitja Bonca
Posting Maven
2,561 posts since May 2009
Reputation Points: 642
Solved Threads: 486
Skill Endorsements: 13
Question Answered as of 2 Years Ago by
Mitja Bonca
and
jockeyvn