最近我发现了一个错误,但无法修复,甚至试图更改参数,但没有任何帮助。 这是我面临的错误,
************** Exception Text **************
System.ArgumentException: Parameter '_IDFID' not found in the collection.
at MySql.Data.MySqlClient.MySqlParameterCollection.GetParameterFlexible(String parameterName, Boolean throwOnNotFound)
at MySql.Data.MySqlClient.StoredProcedure.GetAndFixParameter(String spName, MySqlSchemaRow param, Boolean realAsFloat, MySqlParameter returnParameter)
at MySql.Data.MySqlClient.StoredProcedure.CheckParameters(String spName)
at MySql.Data.MySqlClient.StoredProcedure.Resolve(Boolean preparing)
at MySql.Data.MySqlClient.MySqlCommand.ExecuteReader(CommandBehavior behavior)
at MySql.Data.MySqlClient.MySqlCommand.ExecuteNonQuery()
at Testme.Form3.button1_Click(Object sender, EventArgs e) in C:\Users\Modather\source\repos\Testme\Testme\Form3.cs:line 35
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
我真的不知道问题出在哪里,但这是我的MySQL保存过程
CREATE DEFINER=`sql7258326`@`%` PROCEDURE `MemberEditORAdd`(
_IDFID int,
MemberName varchar(45),
MemberRank varchar(45),
MemberWarn varchar(45),
MemberJoinDate varchar(45)
)
BEGIN
IF IDFID = 0 THEN
INSERT INTO KODCP (IDFID,MEMBRNAME,MEMBRRANK,MEMBRWARN,MJOINDATE)
VALUES (_IDFID,MemberName,MemberRank,MemberWarn,MemberJoinDate);
ELSE
UPDATE KODCP
SET
MEMBRNAME = MemberName,
MEMBRRANK = MemberRank,
MEMBRWARN = MemberWarn,
MJOINDATE = MemberJoinDate
WHERE IDFNUB = _IDFID;
END IF;
END
在VB中编写的调用上述代码的代码是
private void button1_Click(object sender, EventArgs e)
{
using (MySqlConnection mysqlCon = new MySqlConnection(connectionString))
{
mysqlCon.Open();
MySqlCommand mysqlCmd = new MySqlCommand("MemberEditORAdd",mysqlCon);
mysqlCmd.CommandType = CommandType.StoredProcedure;
mysqlCmd.Parameters.AddWithValue("IDFID", IDFID);
mysqlCmd.Parameters.AddWithValue("MEMBRNAME", MemberName.Text.Trim());
mysqlCmd.Parameters.AddWithValue("MEMBRRANK", MemberRank.Text.Trim());
mysqlCmd.Parameters.AddWithValue("MEMBRWARN", MemberWarn.Text.Trim());
mysqlCmd.Parameters.AddWithValue("MJOINDATE", MemberJoinDate.Text.Trim());
mysqlCmd.ExecuteNonQuery();
MessageBox.Show("Operation Done!");
}
}
感谢您的关注,希望您能帮助我修复它,感谢您为我提供帮助<3
答案 0 :(得分:1)
CREATE DEFINER='sql7258326'@'%' PROCEDURE 'MemberEditORAdd'( _IDFID int,***
您已经按照上面的步骤创建了过程,但是您正在尝试按以下步骤使用它
mysqlCmd.Parameters.AddWithValue("IDFID", IDFID);
您需要使用正确的变量名来更改对方法的调用,如mysqlCmd.Parameters.AddWithValue("_IDFID", IDFID);
此行也没有名为IDFID的Procedure参数
IF IDFID = 0 THEN
对数据库运行以下代码:
IF IDFID = 0 THEN
INSERT INTO KODCP (IDFID,MEMBRNAME,MEMBRRANK,MEMBRWARN,MJOINDATE)
VALUES (_IDFID,MemberName,MemberRank,MemberWarn,MemberJoinDate);
ELSE
UPDATE KODCP
SET
MEMBRNAME = MemberName,
MEMBRRANK = MemberRank,
MEMBRWARN = MemberWarn,
MJOINDATE = MemberJoinDate
WHERE IDFNUB = _IDFID;
END IF;
END
上面写着INSERT INTO KODCP (IDFID, MEMBRNAME, MEMBRRANK, MEMBRWARN, MJOINDATE)
,表示
将值插入到名为IDFID, MEMBRNAME, MEMBRRANK, MEMBRWARN, MJOINDATE
的表中名为KODCP
的列中
它还说要从下面的变量列表中分别提供这些参数的值
_IDFID, MemberName, MemberRank, MemberWarn, MemberJoinDate
这意味着粘贴到过程中的变量必须为_IDFID, MemberName, MemberRank, MemberWarn, MemberJoinDate
此代码:
using (MySqlConnection mysqlCon = new MySqlConnection(connectionString))
{
mysqlCon.Open();
MySqlCommand mysqlCmd = new MySqlCommand("MemberEditORAdd",mysqlCon);
mysqlCmd.CommandType = CommandType.StoredProcedure;
mysqlCmd.Parameters.AddWithValue("IDFID", IDFID);
mysqlCmd.Parameters.AddWithValue("MEMBRNAME", MemberName.Text.Trim());
mysqlCmd.Parameters.AddWithValue("MEMBRRANK", MemberRank.Text.Trim());
mysqlCmd.Parameters.AddWithValue("MEMBRWARN", MemberWarn.Text.Trim());
mysqlCmd.Parameters.AddWithValue("MJOINDATE", MemberJoinDate.Text.Trim());
mysqlCmd.ExecuteNonQuery();
MessageBox.Show("Operation Done!");
}
应替换为以下代码:
using (MySqlConnection mysqlCon = new MySqlConnection(connectionString))
{
mysqlCon.Open();
MySqlCommand mysqlCmd = new MySqlCommand("MemberEditORAdd",mysqlCon);
mysqlCmd.CommandType = CommandType.StoredProcedure;
mysqlCmd.Parameters.AddWithValue("_IDFID", IDFID);
mysqlCmd.Parameters.AddWithValue("MemberName", MemberName.Text.Trim());
mysqlCmd.Parameters.AddWithValue("MemberRank", MemberRank.Text.Trim());
mysqlCmd.Parameters.AddWithValue("MemberWarn", MemberWarn.Text.Trim());
mysqlCmd.Parameters.AddWithValue("MemberJoinDate", MemberJoinDate.Text.Trim());
mysqlCmd.ExecuteNonQuery();
MessageBox.Show("Operation Done!");
}
您的支票必须更改为
IF _IDFID = 0 THEN