gpt4 book ai didi

vb.net - 使用 VB.NET 执行存储过程

转载 作者:行者123 更新时间:2023-12-04 14:59:03 25 4
gpt4 key购买 nike

这是我的程序

ALTER PROCEDURE sp_addUser
@UserName nvarchar(50),
@Prenom nvarchar(50),
@Nom nvarchar(50),
@Mail nvarchar(50),
@Password char(8),
@Addresse nvarchar(100),
@Ville nvarchar(50),
@Province nvarchar(50),
@PostalCode char(6),
@Pays nvarchar(50),
@AnimalGenre nvarchar(50),
@NomAnimal nvarchar(50),
@Race nvarchar(50)
AS
BEGIN
INSERT INTO Client
VALUES (@UserName,@Prenom,@Nom,@Mail,@Password,@Addresse,@Ville,@Province,@PostalCode,@Pays,@AnimalGenre,@NomAnimal,@Race);
END

我认为这对存储过程没问题

现在是在数据库中添加值的代码

Sub sp_addUser()

Dim intRowsAff As Integer

lblErrMsg.Text = ""
lblRecsAff.Text = ""

Dim connectionString As String = WebConfigurationManager.ConnectionStrings("BecsEtMuseauxSQL").ConnectionString
Dim con As SqlConnection = New SqlConnection(connectionString)

Dim cmd As New SqlCommand("sp_addUser", con)

cmd.CommandType = CommandType.StoredProcedure
cmd.Parameters.Add("@UserName", SqlDbType.VarChar, 50).Value = txtUserName.Text
cmd.Parameters.Add("@Prenom", SqlDbType.VarChar, 50).Value = txtPrenom.Text
cmd.Parameters.Add("@Nom", SqlDbType.NVarChar, 50).Value = txtNom.Text
cmd.Parameters.Add("@Mail", SqlDbType.NVarChar, 50).Value = txtMail.Text
cmd.Parameters.Add("@Password", SqlDbType.Char, 8).Value = txtPass.Text
cmd.Parameters.Add("@Addresse", SqlDbType.NVarChar, 100).Value = txtAdresse.Text
cmd.Parameters.Add("@Ville", SqlDbType.NVarChar, 50).Value = txtVille.Text
cmd.Parameters.Add("@Province", SqlDbType.NVarChar, 50).Value = txtProvince.Text
cmd.Parameters.Add("@PostalCode", SqlDbType.Char, 6).Value = txtPostal.Text
cmd.Parameters.Add("@Pays", SqlDbType.NVarChar, 50).Value = txtPays.Text
cmd.Parameters.Add("@AnimalGenre", SqlDbType.NVarChar, 50).Value = rblAnimal.Text
cmd.Parameters.Add("@NomAnimal", SqlDbType.NVarChar, 50).Value = txtAnimal.Text
cmd.Parameters.Add("@Race", SqlDbType.NVarChar, 50).Value = txtRace.Text

Try
cmd.Connection.Open()
intRowsAff = cmd.ExecuteNonQuery()
Catch ex As Exception
lblErrMsg.Text = ex.Message & ex.Source
End Try
lblRecsAff.Text = intRowsAff & " record(s) inserted"
cmd.Connection.Close()
End Sub

在我执行方法后 VS 说我必须为过程 sp_addUser 指定很多参数

我不明白为什么会产生错误!

最佳答案

只需将您的 Sp 与代码隐藏方法同步并将参数设置为 sp。

Dim dt As New DataTable
Dim sqlpr1 As New List(Of SqlParameter)

Dim cmd As New SqlCommand()

cmd.CommandType = CommandType.StoredProcedure
cmd.CommandText = "[sp_ItemPackingList]"
cmd.Parameters.Add("@Date", SqlDbType.DateTime).Value = dateDate.Text.Trim()
cmd.Parameters.Add("@Thk", SqlDbType.VarChar).Value = txtPendQty.Text.Trim()
cmd.Parameters.Add("@Dia", SqlDbType.VarChar).Value = txtPendQty.Text.Trim()
Try
cmd.ExecuteNonQuery()
lblMessage.Text = "Record inserted successfully"
Catch ex As Exception
Throw ex
obj.GetDataTable("[sp_ItemPackingList]", sqlpr1)

End Try

关于vb.net - 使用 VB.NET 执行存储过程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8663940/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com