在Vb.net中使用存储过程

时间:2013-11-15 04:17:08

标签: vb.net stored-procedures

我尝试通过调用存储过程将数据插入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'Me',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()

1 个答案:

答案 0 :(得分:0)

你拼错你的参数和sproc名称:

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()