ExecuteNonQuery始终返回0

时间:2019-04-04 01:24:11

标签: vb.net

我在vb项目上有一个addEmployee表单,该表单已连接到本地主机上的数据库。我想在添加员工之前检查数据库中是否存在员工。代码工作正常,并且在数据库中没有相似条目时添加员工,而在存在相似条目时不添加员工。但是,即使添加成功,消息框也始终显示“无法添加用户”。我尝试检查ExecuteNonQuery的值是什么,并且始终为0。

//the code in the addEmployee form

Dim cmd As New MySqlCommand()
    cmd.Connection = conn
    cmd.CommandText = "addEmployee"
    cmd.CommandType = CommandType.StoredProcedure


    cmd.Parameters.AddWithValue("Employee_ID", tbNEmployeeID.Text)
    cmd.Parameters.AddWithValue("First_Name", tbNFirstName.Text)
    cmd.Parameters.AddWithValue("Last_Name", tbNLastName.Text)
    cmd.Parameters.AddWithValue("Middle_Initial", tbNMiddleInitial.Text)

    conn.Open()

    MsgBox(cmd.ExecuteNonQuery)
    If cmd.ExecuteNonQuery Then
        MsgBox("user succesfully added")
    Else
        MsgBox("failed to add user")
    End If

    conn.Close()

//db addEmployee procedure

begin

set @eid = Employee_ID;
set @fname = First_Name;
set @lname =Last_Name;
set @mi = Middle_Initial;
set @idexist = (select count(*) from user where EmployeeID = @eid);


if( @eid = '' or @fname = '' or @lname = '' or @mi = '') THEN select 
'Please fill out all empty parameters!';
 elseif(@idexist = 1) then select 'User already exist!';
 elseif(@idexist = 0) THEN
 insert into user values(id,@eid,@fname,@lname,@mi,now(),UpdatedAt);
 select 'User added successfully!';

end IF;
END

我希望ExecuteNonQuery返回0/1

我对此还是很陌生,所以如果您可以简化答案。谢谢

0 个答案:

没有答案