ASP.NET - Multiple DataAdapter Bind with a gridview

Asked By Chempaka Sari on 20-Oct-10 08:30 AM
Hi...

Anyone knows that whether can @ can't oledbadapter bind with only a gridview?

It is because I have multiple sql statement that need to be combine @ appear in only a single gridview..

anyone have ideas to share???

thanks!
Reena Jain replied to Chempaka Sari on 20-Oct-10 08:38 AM
hi,

you can use union to combine all queries and assign this how to gridview control. but to use the union column name must me same in all queries you are using.

hope this will help you
Sagar P replied to Chempaka Sari on 20-Oct-10 09:49 AM
No i think you can't bind two result set with single gridview. What you can do is, you can modify your query in such a way that you will get the result set in single DataApapter so that you can fill DataSet with it.
Once you have dataset with the required resultset you can easily bind it to gridview.....

So you have to modify your 2 queries into one to get proper resultset.......
undhad ashwin replied to Chempaka Sari on 20-Oct-10 05:45 PM
Try This below code

 Public void bindRecord()
    {
    SqlConnection con =new SqlConnection(ConfigurationManager.
       ConnectionStrings["ConnectionString"].ConnectionString.ToString();)
    SqlCommand cmd=new SqlCommand();
     SqlCommand cmd1=new SqlCommand();
    cmd.connection=con;
    con.open();
    cmd.commandText="SELECT * FROM tablename";
      cmd1.commandText="SELECT * FROM tablename1";
    SqlDataAdapter da=new SqlDataAdapter(cmd);
     SqlDataAdapter da1=new SqlDataAdapter(cmd1);
    Dataset ds=new Dataset();
      Dataset ds1=new Dataset();
    da.fill(ds);
        da1.fill(ds1);
    cmd.ExecuteNonQuery();
      cmd1.ExecuteNonQuery();
      ds.Merge(ds1,true);
    grdview.DataSource=ds;
    grdview.DataBind();
    con.close();
}
Chempaka Sari replied to undhad ashwin on 20-Oct-10 07:25 PM
Hi everyone....I already used merged in my code..It works but the data inside the row did not append but it go below...

This is my code and the result:

Imports System.ComponentModel
Imports System.Web.UI
Imports System.Data
Imports System.Data.SqlClient
Imports System.Data.OleDb
 
Partial Class Transpose_YaAllah_bantu_kami
  Inherits System.Web.UI.Page
 
 
  Dim con As OleDbConnection
  Dim dbProvider As String
  Dim dbSource As String
 
  Dim SumRep_B As OleDbDataAdapter
  Dim SumRep_S As OleDbDataAdapter
  Dim SumRep_SS As OleDbDataAdapter
  Dim ds1 As DataSet
  Dim ds2 As DataSet
  Dim ds3 As DataSet
 
 
  Public Sub page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
 
    con = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("CSG.mdb"))
 
 
    dbProvider = "PROVIDER=Microsoft.Jet.OLEDB.4.0;"
    dbSource = "Data Source =C:\Users\MC-dy\Desktop\CSG\CSG.mdb"
 
 
    con.ConnectionString = dbProvider & dbSource
 
    con.Open()
 
    SumRep_B = New OleDbDataAdapter("Select * From SummTabb_Crosstab_Board", con)
    SumRep_S = New OleDbDataAdapter("Select * From SummTabb_Crosstab_S", con)
    SumRep_SS = New OleDbDataAdapter("Select * From SummTabb_Crosstab_SS", con)
 
    ds1 = New DataSet()
    ds2 = New DataSet()
    ds3 = New DataSet()
 
 
    SumRep_B.Fill(ds1, "Table1")
    SumRep_S.Fill(ds2, "Table1")
    SumRep_SS.Fill(ds3, "Table1")
 
    ds1.Merge(ds2, False, MissingSchemaAction.Add)
    ds1.Merge(ds3, False, MissingSchemaAction.Add)
 
    'Me.GridView1.Visible = True
 
    GridView1.DataSource = ds1
 
    'GridView1.DataMember = "Table1"
 
    GridView1.DataBind()
 
    con.Close()
 
  End Sub
End Class