Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3877614
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T22:31:05+00:00 2026-05-19T22:31:05+00:00

SqlDataAdapter adap = new SqlDataAdapter(Select * from Contentpagenav;Select * from Employees,conn); DataSet ds =

  • 0
SqlDataAdapter adap = new SqlDataAdapter("Select * from Contentpagenav;Select * from Employees",conn);
        DataSet ds = new DataSet();
        conn.Open();
        adap.TableMappings.Add("ContentPagenav", "Table1");
        adap.TableMappings.Add("Employees", "Table2");
        adap.Fill(ds, "Table1");
        adap.Fill(ds, "Table2");
        GridView1.DataSource = ds.Tables["Table1"];
        GridView1.DataBind();
        GridView2.DataSource = ds.Tables["Table2"];
        GridView2.DataBind();
        conn.Close();

I am getting the first table data in both the gridviews. What am I doing wrong?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T22:31:05+00:00Added an answer on May 19, 2026 at 10:31 pm

    did you tried by doing this

    SqlDataAdapter adap = new SqlDataAdapter("Select * from Contentpagenav;Select * from Employees",conn);
        DataSet ds = new DataSet();
        conn.Open();
        // don't map
        //adap.TableMappings.Add("ContentPagenav", "Table1");
        //adap.TableMappings.Add("Employees", "Table2");
        //adap.Fill(ds, "Table1");
        //adap.Fill(ds, "Table2");
    
        // access tables by index instead of name
        GridView1.DataSource = ds.Tables[0];
        GridView1.DataBind();
        GridView2.DataSource = ds.Tables[1];
        GridView2.DataBind();
        conn.Close();
    

    Edit 1: There are some mistakes with your code

    SqlDataAdapter adap = new SqlDataAdapter("Select * from Contentpagenav;Select * from Employees",conn);
    DataSet ds = new DataSet();
    conn.Open();
    // the select statement only return Table, Table1, Table2 and so on
    // it don't know About ContentPagenav or Employees
    // so I am maping Table to MyTable1
    //and Table1 to MyTable2
    adap.TableMappings.Add("Table", "MyTable1");
    adap.TableMappings.Add("Table1", "MyTable2");
    
    // don't do this, it will discard your mapping,
    // it will return
    // Table1, Table2, and so on
    //adap.Fill(ds, "Table1");
    
    // just fill your dataset, and it will keep your mapping
    adap.Fill(ds);
    
    // access tables by your suggested name
    GridView1.DataSource = ds.Tables["MyTable1"];
    GridView1.DataBind();
    GridView2.DataSource = ds.Tables["MyTable2"];
    GridView2.DataBind();
    conn.Close();
    

    For more understandings Table Mapping in ADO.NET

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

SqlConnection con1 = new SqlConnection(ConfigurationManager.ConnectionStrings[GVRAgencyConnectionString1].ConnectionString); con1.Open(); SqlDataAdapter da = new SqlDataAdapter(select weight,mrp_pack,no_of_pack,mrp_master_pack from dbo.purchase_order
SqlConnection conn = new SqlConnection(); DataSet ds = new DataSet(); SqlDataAdapter da = new
when i run a query like this: SqlDataAdapter dap = new SqlDataAdapter(select * from
I've got a problem: SqlDataAdapter da = new SqlDataAdapter(SELECT dbo.User.name FROM dbo.User, con); DataTable
private static DataSet GetAuctionItemsDataSet() { SqlDataAdapter adapt = new SqlDataAdapter(); adapt = DataAdapter; DataSet
I've imported a DataTable from a SQL Database using SqlDataAdapter and Fill-Method. My datatable
using (IDbCommand command = new SqlCommand()) { IDbDataAdapter adapter = new SqlDataAdapter(); DataSet ds
Dim dt As New DataTable Dim da As New SqlDataAdapter(s, c) c.Open() If Not
I used sqlDataAdapter to fill one of my DataTables in a dataset. although the
I transfer a SQL Table from a SQL Database with SQLDataAdapter and Fill-Method to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.