-1

How can I delete a row from excel sheet based on product id provided in textbox1. Using that product_id it should delete the whole row from excel sheet & display updated data in datagridview?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129

2 Answers2

1

if you'll look at here you'll find explanation on how to delete using Range.Delete Method. this method is for deleting from exel and as Karthik posted you can do

 ((Range)worksheet.Rows[i]).Delete(shiftDirection)

for your code in order do delete data from row i. the shiftDirection is optional and Specifies how to shift cells to replace deleted cells.

No Idea For Name
  • 11,411
  • 10
  • 42
  • 70
0
        private void deleteButton_Click(object sender, EventArgs e)


         {


        OleDbConnection myConn = new OleDbConnection(connectionString);

        string excelDelete = "DELETE FROM [Sheet1$] WHERE ID = '" + dgvExcelList["ID", dgvExcelList.CurrentRow.Index].Value.ToString() + "'";//modify as your need
        OleDbCommand Deletecmd = new OleDbCommand(excelDelete, myConn);
        myConn.Open();
        Deletecmd.ExecuteNonQuery();
        myConn.Close();
        /*code to update datagridview*/



    }
roanjain
  • 1,252
  • 4
  • 14
  • 32