当执行到达时cmd.ExecuteNonQuery()必须声明标量变量,我收到错误:
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();
Run Code Online (Sandbox Code Playgroud)
代替
string commandText = "update groups set subjectline ='" + txtSubjectLine.Text + "',data= @data where groupid = " + ddlGroup.SelectedItem.Value + " ";
Run Code Online (Sandbox Code Playgroud)
和
string commandText = "update groups set subjectline ='" + txtSubjectLine.Text + "',data= ? where groupid = " + ddlGroup.SelectedItem.Value + " ";
Run Code Online (Sandbox Code Playgroud)
即,将“@data”替换为“?” 在命令文本中。这是使用 OleDbCommand 指定参数占位符的方式。
以下是编辑后的原文:
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();
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3208 次 |
| 最近记录: |