anjumathi kumar

anjumathi kumar

  • NA
  • 54
  • 64.2k

How to update excel through grid

Aug 16 2011 3:55 AM

Hi  this is my coding

 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 that

1 mathi  b.sc
2 suruthi m.a 

I have like this in my excel and i added checkbox in gridview asp.net .if i check the checkbox it want to delete the record in gridview and excel.I imported the excel content to grid..so i want to update excel through grid any idea?









Answers (1)