Click here to Skip to main content
15,895,799 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi, this is my code:

C#
protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                String strConn = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=F:\\Book1.xlsx;Extended Properties=Excel 8.0;";
                DataTable ds = new DataTable();
                OleDbDataAdapter da = new OleDbDataAdapter("Select * from[Sheet1$]", strConn);
                da.Fill(ds);
                grvPatient.DataSource = ds;
                grvPatient.DataBind();
            }
        }


        string PatientId = "";
        protected void btn_save(object sender, EventArgs e)
        {
            for (int i = 0; i < grvPatient.Rows.Count; i++)
            {
                bool chk = ((CheckBox)grvPatient.Rows[i].FindControl("myCheckBox")).Checked;
                if (chk == true)
                {
                    PatientId = grvPatient.Rows[i].Cells[1].Text;
                    string Patient = grvPatient.Rows[i].Cells[2].Text;
                    string Amount = grvPatient.Rows[i].Cells[3].Text;
                    string Doctor = grvPatient.Rows[i].Cells[4].Text;
                    string status = grvPatient.Rows[i].Cells[5].Text;
                    dbquery.InsertChecked(Int32.Parse(PatientId), Patient, Int32.Parse(Amount), Doctor);



 dbquery.deleteRecord(Int32.Parse(PatientId));
                    //update the status to MS Excel
                    String strConn = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=F:\\Book1.xlsx;Extended Properties=Excel 8.0;";
                    DataTable ds = new DataTable();
                    OleDbDataAdapter da = new OleDbDataAdapter("Select * from[Sheet1$]", strConn);
                    da.Fill(ds);
                    grvPatient.DataSource = ds;
                    grvPatient.DataBind();
}
}
}


I am trying to update the records in Excel through gridview.

I have three records like this:
1 mathi b.sc
2 suruthi m.a


I have like this in my Excel and I have added a checkbox in gridview asp.net. If I check the checkbox it wants to delete the record in gridview and Excel. I imported the Excel content to grid, so I want to update Excel through grid, any ideas?
Posted
Updated 15-Aug-11 23:32pm
v2

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