0

我想在我的表中插入值。(数据库:-DB2)基于文本框获取的值。我正在创建一个演示页面,其中我的文本框将获得一个整数值,并且在单击按钮时它必须插入到数据库中。AddWithValue()问题是当我们处理 DB2 Connection 时没有调用这样的方法。现在我如何从文本框中获取值,以便我可以插入表格?

protected void Button3_Click(object sender, EventArgs e)
        {
            String pass = TextBox4.Text;
            DB2Connection connect = new DB2Connection("Database=SAMPLE;UserID=xxxxxxx;Password=xxxxxx;Server=xx.xx.xx.xx:50000");
            DB2Command cmd = new DB2Command();
            cmd.Connection = connect;
            cmd.CommandText = "INSERT INTO Demo VALUES (@pass)";
            cmd.Parameters.AddWithValue("@pass", pass);
            connect.Open();
            cmd.ExecuteNonQuery();
            connect.Close();
        }

错误 1:

IBM.Data.DB2.DB2ParameterCollection 不包含“AddWithValue”的定义,并且找不到接受“IBM.Data.DB2.DB2ParameterCollection”类型的第一个参数的扩展方法“AddWithValue”

此外,在cmd.ExecuteNonQuery()它向我显示错误 ERROR 2 时:

{函数评估已禁用,因为之前的函数评估超时。您必须继续执行才能重新启用函数评估。}

4

1 回答 1

0

您始终可以使用较长的语法设置参数,例如

 DB2Parameter p1 = new DB2Parameter();
 p1.ParameterName = "@pass";
 p1.DB2Type = DB2Type.Double;
 p1.Value = 2;

 cmd.Parameters.Add(p1);
于 2013-01-03T12:14:48.033 回答