I am getting an error when execution reaches cmd.ExecuteNonQuery()
which says Must declare the scalar variable:
OleDbCommand cmd = new OleDbCommand();
cmd.Connection = Connection;
cmd.CommandTimeout = 0;
string commandText = "update groups set subjectline ='" + txtSubjectLine.Text + "',data= @data where groupid = " + ddlGroup.SelectedItem.Value + " ";
cmd.CommandText = commandText;
cmd.CommandType = CommandType.Text;
cmd.Parameters.Add("@Data",OleDbType.VarBinary);
cmd.Parameters["@Data"].Value = binarydata;
cmd.ExecuteNonQuery();
Replace
string commandText = "update groups set subjectline ='" + txtSubjectLine.Text + "',data= @data where groupid = " + ddlGroup.SelectedItem.Value + " ";
with
string commandText = "update groups set subjectline ='" + txtSubjectLine.Text + "',data= ? where groupid = " + ddlGroup.SelectedItem.Value + " ";
that is, replace "@data" with "?" in the command text. This is how you specify parameter placeholders with OleDbCommand.
Here's the edited original:
OleDbCommand cmd = new OleDbCommand();
cmd.Connection = Connection;
cmd.CommandTimeout = 0;
cmd.CommandText = "update groups set subjectline ='" + txtSubjectLine.Text + "', data = ? where groupid = " + ddlGroupSelectedItem.Value;
cmd.CommandType = CommandType.Text;
cmd.Parameters.Add("p1", OleDbType.VarBinary);
cmd.Parameters["p1"].Value = binarydata;
cmd.ExecuteNonQuery();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With