日期:2014-05-18  浏览次数:21636 次

如何声明标量变量
下面是在dataset.designer中添加的删除语句,删除后保存就会出现错误必须声明标量变量 "@IsNull_id",还请大虾指点

this._adapter.DeleteCommand = new System.Data.SqlClient.SqlCommand();
  this._adapter.DeleteCommand .Connection = this.Connection;
  this._adapter.DeleteCommand.CommandText = @"DELETE FROM [dbo].[Table_1] WHERE (((@IsNull_id = 1 AND [id] IS NULL) OR ([id] = @Original_id)) AND ((@IsNull_name = 1 AND [name] IS NULL) OR ([ad] = @Original_stuName)) AND ((@IsNull_ad = 1 AND [ad] IS NULL) OR ([ad] = @Original_ad)))";
  this._adapter.DeleteCommand .CommandType = System.Data.CommandType.Text;
  this._adapter.DeleteCommand .Parameters.Add(new System.Data.SqlClient.SqlParameter("@id", System.Data.SqlDbType.NChar, 0, System.Data.ParameterDirection.Input, 0, 0, "id", System.Data.DataRowVersion.Current, false, null, "", "", ""));
  this._adapter.DeleteCommand .Parameters.Add(new System.Data.SqlClient.SqlParameter("@name", System.Data.SqlDbType.NChar, 0, System.Data.ParameterDirection.Input, 0, 0, "name", System.Data.DataRowVersion.Current, false, null, "", "", ""));
  this._adapter.DeleteCommand .Parameters.Add(new System.Data.SqlClient.SqlParameter("@ad", System.Data.SqlDbType.NChar, 0, System.Data.ParameterDirection.Input, 0, 0, "ad", System.Data.DataRowVersion.Current, false, null, "", "", ""));


------解决方案--------------------
string constr = "连接字符串";
SqlConnection connect = new SqlConnection(constr);
connect.Open();
string delStr = "delete from userinfo where Uname='" + textBox1.Text + "'";//删除表userinfo中字段值与textBox1.Text一样的行
SqlCommand cmd = new SqlCommand(delStr, connect);
cmd.ExecuteNonQuery();