Click here to Skip to main content
15,887,135 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I am using excel as my db and displaying data in a grid view. The excel contains only two columns "Name" and "Value" and no primary/unique key like a ID or index. I tried to update directly the cell of the excel by using the gridview row index but getting an error "System.Data.OleDb.OleDbException: No value given for one or more required parameters."
Here's what I tried
GridViewRow row = (GridViewRow)gvExcelFile.Rows[e.RowIndex];
TextBox TxtEditName = (TextBox)row.FindControl("TxtEditName");
TextBox TxtEditValue = (TextBox)row.FindControl("TxtEditValue");

string enm = TxtEditName.Text;
string evl = TxtEditValue.Text;
int editindex = gvExcelFile.EditIndex;
int currentindex = e.RowIndex+1;
string editquery = "UPDATE [Sheet1$] set [Sheet1$A"+currentindex+"]=? ,[Sheet1$B"+currentindex+"]=?";
gvExcelFile.EditIndex = -1;
conn.Open();

OleDbCommand editcmd = new OleDbCommand(editquery, conn);
editcmd.Parameters.AddWithValue("[Sheet1$A"+currentindex+"]", enm);
editcmd.Parameters.AddWithValue("[Sheet1$B"+currentindex+"]", evl);
editcmd.ExecuteNonQuery();
conn.Close();
gvbind();
Posted
Updated 9-Oct-14 0:57am
v2

1 solution

 
Share this answer
 

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