gpt4 book ai didi

asp.net - 错误 : Must declare the scalar variable "@data"

转载 作者:行者123 更新时间:2023-12-04 20:17:14 26 4
gpt4 key购买 nike

执行到 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();

最佳答案

代替

string commandText = "update groups set subjectline ='" +    txtSubjectLine.Text + "',data= @data where groupid = " + ddlGroup.SelectedItem.Value + " ";


string commandText = "update groups set subjectline ='" +    txtSubjectLine.Text + "',data= ? where groupid = " + ddlGroup.SelectedItem.Value + " ";

也就是说,将“@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();

关于asp.net - 错误 : Must declare the scalar variable "@data",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10796310/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com