I'm trying to make an .aspx page which would allow me to change values in the database. It has a datagrid which shows everything from one database table, and allows me to edit the data row by row. Everything goes smoothly as anything, but when I try i update the database with SQL query, i get error. Here is the error:
Exception Details: System.Data.OleDb.OleDbException: No value given for one or more required parameters.
Source Error:
Line 115:
Line 116: //Kun parametrit on luotu, suoritetaan kysely
Line 117: objCommand.ExecuteNonQuery();
Line 118: //Suljetaan yhteys
Line 119: MyConn.Close();
Source File: c:\inetpub\wwwroot\phoenix\search.aspx.cs Line: 117
I just can't see what i'm missing, because I have triple checked my code and I don't see any errors in it. I bet this is very simple problem what i just can't see. I have also checked with debugger that the parameters DO get value in the code (for example: "parameterprodID.Value = IDcolumn" gives value of 2 as it is second row), so I'm very clueless what is wrong with this. Here is the actual update code:
string strSQL = "UPDATE [Categories] SET [Category Name] = @Name WHERE [Category ID] = @ProductID";
OleDbConnection MyConn = new OleDbConnection(ConfigurationSettings.AppSettings["strConn"]);
MyConn.Open();
OleDbCommand objCommand = new OleDbCommand(strSQL, MyConn);
objCommand.CommandType = CommandType.Text;
OleDbParameter parameterTarget = new OleDbParameter("@Name", OleDbType.VarWChar);
parameterTarget.Value = ((TextBox) e.Item.Cells[2].Controls[0]).Text;
objCommand.Parameters.Add(parameterTarget);
OleDbParameter parameterprodID = new OleDbParameter("@ProductID", OleDbType.Integer);
parameterprodID.Value = IDcolumn;
objCommand.Parameters.Add(parameterprodID);
objCommand.ExecuteNonQuery();
MyConn.Close();