codetoad.com
  ASP Shopping CartForum & BBS
  - all for $20 from CodeToad Plus!
  
  Home || ASP | ASP.Net | C++/C# | DHTML | HTML | Java | Javascript | Perl | VB | XML || CodeToad Plus! || Forums || RAM 
Search Site:
Search Forums:
  problem in ado.net  anant at 06:35 on Wednesday, December 13, 2006
 


i've to show data from 3 tables in a datagird, the problem is
how to fill dataadapter with Fill method , shud i take 3 dataadapter objects and 3 dataset objects???? cud anybody suggest me.?????

  Re: problem in ado.net  ymdomar at 08:43 on Friday, December 15, 2006
 

You achieve this using one adaptor and one dataset. In side dataset, u can store multiple tables. Use Fill method to fill each table.

Once you get all three tables in dataset, create a you custom table using Datatable and merge three tables. Then create dataview for that datatable. Use this dataview as datagrid datasource. Following code snap would help to understand…


// Sql connection..
SqlConnection con = new SqlConnection(connectionString);

// Create Data Adaptor
SqlDataAdapter DAEmp = new SqlDataAdapter();

// Sql command for selecting tables
SqlCommand Dcom = new SqlCommand();

Dcom.CommandText = @"Select * from table1"; // first table
Dcom.Connection = con;
DAEmp.SelectCommand = Dcom;

// create Data set
DataSet DSEmp = new DataSet();

DAEmp.Fill(DSEmp,"Table1"); // Filling first table

Dcom.CommandText = @"select * from table2"; // Second table
DAEmp.SelectCommand = Dcom;
DAEmp.Fill(DSEmp,"Table2"); // Filling second table

Dcom.CommandText = @"select * from table3"; // Third table
DAEmp.SelectCommand = Dcom;
DAEmp.Fill(DSEmp,"Table3"); // Filling third table

// Create table for merger all three tables

DataTable tb = new DataTable();

// Data column to add in table
DataColumn dc = new DataColumn("Col1",typeof(string));
DataColumn dc1 = new DataColumn("Col2",typeof(string));
tb.Columns.Add(dc);
tb.Columns.Add(dc1);

// Fetching all three table – to insert row in table
for ( int k = 0; k < DSEmp.Tables.Count; k++ )
{
// Fetching all row of each table – to insert row in table
for ( int i = 0; i < DSEmp.Tables[k].Rows.Count ; i++ )
{
DataRow dr = tb.NewRow();
dr["Col1"] = DSEmp.Tables[k].Rows[0].ToString();
dr["Col1"] = DSEmp.Tables[k].Rows[1].ToString();
tb.Rows.Add(dr);
}
}

// Creates dataview of the table
DataView dv = new DataView(tb);

// Assigning Dataview to datagrid datasource
DataGrid1.DataSource = dv;
DataGrid1.DataBind();




  Re: problem in ado.net  ymdomar at 08:44 on Friday, December 15, 2006
 

You achieve this using one adaptor and one dataset. In side dataset, u can store multiple tables. Use Fill method to fill each table.

Once you get all three tables in dataset, create a you custom table using Datatable and merge three tables. Then create dataview for that datatable. Use this dataview as datagrid datasource. Following code snap would help to understand…


// Sql connection..
SqlConnection con = new SqlConnection(connectionString);

// Create Data Adaptor
SqlDataAdapter DAEmp = new SqlDataAdapter();

// Sql command for selecting tables
SqlCommand Dcom = new SqlCommand();

Dcom.CommandText = @"Select * from table1"; // first table
Dcom.Connection = con;
DAEmp.SelectCommand = Dcom;

// create Data set
DataSet DSEmp = new DataSet();

DAEmp.Fill(DSEmp,"Table1"); // Filling first table

Dcom.CommandText = @"select * from table2"; // Second table
DAEmp.SelectCommand = Dcom;
DAEmp.Fill(DSEmp,"Table2"); // Filling second table

Dcom.CommandText = @"select * from table3"; // Third table
DAEmp.SelectCommand = Dcom;
DAEmp.Fill(DSEmp,"Table3"); // Filling third table

// Create table for merger all three tables

DataTable tb = new DataTable();

// Data column to add in table
DataColumn dc = new DataColumn("Col1",typeof(string));
DataColumn dc1 = new DataColumn("Col2",typeof(string));
tb.Columns.Add(dc);
tb.Columns.Add(dc1);

// Fetching all three table – to insert row in table
for ( int k = 0; k < DSEmp.Tables.Count; k++ )
{
// Fetching all row of each table – to insert row in table
for ( int i = 0; i < DSEmp.Tables[k].Rows.Count ; i++ )
{
DataRow dr = tb.NewRow();
dr["Col1"] = DSEmp.Tables[k].Rows[0].ToString();
dr["Col1"] = DSEmp.Tables[k].Rows[1].ToString();
tb.Rows.Add(dr);
}
}

// Creates dataview of the table
DataView dv = new DataView(tb);

// Assigning Dataview to datagrid datasource
DataGrid1.DataSource = dv;
DataGrid1.DataBind();











CodeToad Experts

Can't find the answer?
Our Site experts are answering questions for free in the CodeToad forums








Recent Forum Threads
•  Re: need help!!!
•  Connecting to an https server using NNTP perl
•  Is there an ADMIN!!!!! Is this place maintained!
•  small question
•  Re: Text to Speech Converter
•  Re: Multithreading question
•  Re: This forum sucks.
•  Re: Appending to a file
•  Re: Problems with mkdir


Recent Articles
ASP GetTempName
Decode and Encode UTF-8
ASP GetFile
ASP FolderExists
ASP FileExists
ASP OpenTextFile
ASP FilesystemObject
ASP CreateFolder
ASP CreateTextFile
Javascript Get Selected Text


© Copyright codetoad.com 2001-2006