Click here to Skip to main content
15,883,901 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

am trying to export 2 tables data in one excel sheet.

but it's exporting only 1st table data in excelsheet.

C#
SqlDataAdapter dscmd2 = new SqlDataAdapter("SELECT * FROM DriveInfo; SELECT * FROM NetworkInfo", conn);
            dscmd2.TableMappings.Add("Table", "DriveInfo");
            dscmd2.TableMappings.Add("Table1", "NetworkInfo");
            DataSet ds2 = new DataSet();
            dscmd2.Fill(ds2);

            for (i = 0; i <= ds2.Tables[0].Rows.Count - 1; i++)
            {
                for (j = 0; j <= ds2.Tables[0].Columns.Count - 1; j++)
                {
                    //data = ds.Tables[0].Columns[j].ColumnName.ToString();

                    data = ds2.Tables[0].Rows[i].ItemArray[j].ToString();
                    //xlWorkSheet.Cells[i + 3, j + 1] = data;
                    xlWorkSheet2.Cells[i + 3, j + 1] = data;
                }
            }


Thanks
sam.198979
Posted

1 solution

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900