0

我尝试通过调用存储过程将数据插入 SQL Server,但出现错误。

过程或函数“USP_InsertNguoiDung”需要参数“@idND”,但未提供该参数。

我在 SQL Server 中的存储过程

create proc USP_InsertNguoiDung
    @idND nvarchar(20),
    @tenND nvarchar(100),
    @matkhauND nvarchar(100),
    @phanquyenND nvarchar(100)
as
begin
    insert into nguoidung values(@idND, @tenND, @matkhauND, @phanquyenND)
end

exec USP_InsertNguoiDung '我',N'Mẹ','123','NguoiDung'

我的代码调用存储过程

 'Dim con As SqlConnection = _db.Getcon()
    'con.Open()
    'Cmd = New SqlCommand("USP_InsertPeople", con)
    'Cmd.CommandType = CommandType.StoredProcedure
    'Cmd.Parameters.Add(New SqlParameter("@id", ndDTO.NguoiDungID))
    'Cmd.Parameters.Add(New SqlParameter("@hoten", ndDTO.Hoten))
    'Cmd.Parameters.Add(New SqlParameter("@matkhau", ndDTO.Matkhau))
    'Cmd.Parameters.Add(New SqlParameter("@phanquyen", ndDTO.PhanQuyen))
    'Cmd.ExecuteReader()
    'con.Close()
4

1 回答 1

0

您拼错了参数和存储过程名称:

Dim con As SqlConnection = _db.Getcon()
con.Open()
Cmd = New SqlCommand("USP_InsertNguoiDung", con)
Cmd.CommandType = CommandType.StoredProcedure
Cmd.Parameters.Add(New SqlParameter("@idND", ndDTO.NguoiDungID))
Cmd.Parameters.Add(New SqlParameter("@tenND", ndDTO.Hoten))
Cmd.Parameters.Add(New SqlParameter("@matkhauND", ndDTO.Matkhau))
Cmd.Parameters.Add(New SqlParameter("@phanquyenND", ndDTO.PhanQuyen))
Cmd.ExecuteReader()
con.Close()
于 2013-11-15T04:23:21.160 回答