tags:

views:

428

answers:

1

Hi, I got 2 different EXCEL FILE (.xls).And there is a Column named "KATIP" in excel1.xls , and there is a column named "SAVCI" in excel2.xls.I wanna get this 2 column from excel1.xls and excel2.xls and merge themn into a table named "Nobet" with 2 column "SAVCI" and "KATIP". and show them in Gridview Control in ASP.NET .. I got working codes but there is a problem when i run its getting first column named "KATIP" then getting column named "SAVCI".Not merged showin me like different columns.

  OleDbConnection DBConnection = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=" +

  Server.MapPath("~/App_Data/excel1.xls") + ";" + "Extended Properties=\"Excel 8.0;HDR=Yes\"");

  DBConnection.Open();
  string SQLString = "SELECT * FROM [Page1$]";
  OleDbCommand DBCommand = new OleDbCommand(SQLString, DBConnection);
  OleDbDataAdapter da = new OleDbDataAdapter(DBCommand);
  DataSet ds = new DataSet("Nobet");
  da.Fill(ds,"Nobet");
  DBConnection.Close();
  DBConnection = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=" +Server.MapPath("~/App_Data/excel2.xls") + ";" + "Extended Properties=\"Excel 8.0;HDR=Yes\"");


DBConnection.Open();
  DBCommand = new OleDbCommand(SQLString, DBConnection);
  da = new OleDbDataAdapter(DBCommand);
  da.Fill(ds,"Nobet");
  GridView1.DataSource = ds.Tables["Nobet"];
  GridView1.DataBind();
  DBConnection.Close();

thanx for ur help.

A: 

I solved my problem .. here is ;

    OleDbConnection DBConnection = new
    OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=" +
     Server.MapPath("~/App_Data/savcilik_katip.xls") + ";" + "Extended Properties=\"Excel 8.0;HDR=Yes\"");
    DBConnection.Open();
    OleDbCommand DBCommand = new OleDbCommand("SELECT * FROM [Sayfa1$]", DBConnection);
    OleDbDataAdapter da = new OleDbDataAdapter(DBCommand);
    DataSet ds = new DataSet("Nobet");
    da.Fill(ds, "Nobet");
    DBConnection.Close();
    DBConnection = new
  OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=" +
  Server.MapPath("~/App_Data/savcilik_savci.xls") + ";" + "Extended Properties=\"Excel 8.0;HDR=Yes\"");
    DBConnection.Open();
    DBCommand = new OleDbCommand("SELECT * FROM [Sayfa1$]", DBConnection);
    da = new OleDbDataAdapter(DBCommand);
    da.Fill(ds, "Nobetci");

    DBConnection.Close();
    for (int i = 0; i < ds.Tables["Nobet"].Rows.Count; i++)
    {
        ds.Tables["Nobet"].Rows[i]["SAVCI"] = ds.Tables["Nobetci"].Rows[i]["SAVCI"];
    }

    GridView1.DataSource = ds.Tables["Nobet"];
    GridView1.DataBind();
Ibrahim AKGUN