You must Sign In to post a response.
  • Category: ASP.NET

    How to upload excel file if data exit not to inset that row using asp.net C# ?

    how to upload excel file if data exit not to inset that row ?

    hi , i want to upload excel file into database using asp.net C# ?

    If row already exits then not to inset that row into table ?

    Please help me to this question ?
  • #767522
    Hi,

    Simple First get the excel data into one DataTable like below


    oconn = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + FilePath + ";Extended Properties=Excel 8.0");


    OleDbCommand ocmd = new OleDbCommand("select * from ["Sheet1 "]", oconn);

    oconn.Open();

    OleDbDataReader odr = ocmd.ExecuteReader();

    while (odr.Read())
    {
    DataRow dr = dt1.NewRow();
    dr["ENAME"] = odr["ENAME"].ToString();
    dr["JOB"] = odr["JOB"].ToString();
    dr["MGR"] = odr["MGR"].ToString();
    dr["SAL"] = odr["SAL"].ToString();
    dr["COMM"] = odr["COMM"].ToString();
    dt1.Rows.Add(dr);
    }


    Now you have a data in datatable i.e dt1, now get the data from database and store it into one more datatable i.e dt2. While insert the record into database compare dt1 with dt2 whether the data is present over there or not.

    Hope this will help you...

    --------------------------------------------------------------------------------
    Give respect to your work, Instead of trying to impress your boss.

    N@veen
    Blog : http://naveens-dotnet.blogspot.in/


Sign In to post your comments