我在更新客户表时遇到此错误:
过程或函数'Update_Customer'需要参数'@CustomerPhoto',但未提供。
存储过程代码:
ALTER procedure [dbo].[Update_Customer]
@CustomerID int output,
@CustomerName nvarchar (50),
@CustomerPhoto image,
@CustomerEmail nvarchar(Max),
@CustomerPhone1 nvarchar(12),
@CustomerPhone2 nvarchar(12),
@CustomerAddress nvarchar(Max),
@CustomerFax nvarchar(12),
@CustomerStatus bit,
@CountryID int,
@CityID int,
@Notes nvarchar (Max),
@ModifiedBy nvarchar (30)
AS
BEGIN
UPDATE CustomersTbl
SET CustomerID = @CustomerID,
CustomerName = @CustomerName,
CustomerPhoto = @CustomerPhoto,
CustomerEmail = @CustomerEmail,
CustomerPhone1 = @CustomerPhone1,
CustomerPhone2 = @CustomerPhone2,
CustomerAddress = @CustomerAddress,
CustomerFax = @CustomerFax,
CustomerStatus = @CustomerStatus,
CountryID = @CountryID,
CityID = @CityID,
Notes = @Notes,
ModifiedDate = GETDATE(),
ModifiedBy = @ModifiedBy
WHERE
CustomerID = @CustomerID
END
数据层类代码:
Friend Function Update_Customer(ByVal CustomerID As String, ByVal CustomerName As String, ByVal CustomerEmail As String, ByVal CustomerPhone1 As String, ByVal CustomerPhone2 As String, ByVal CustomerAddress As String, ByVal CustomerFax As String, ByVal CustomerStatus As Boolean, ByVal CountryID As Integer, ByVal CityID As Integer, ByVal Notes As String, ByVal ModifiedBy As String) As String
Dim retval As String
Dim cmd As New SqlCommand("Update_Customer")
cmd.Parameters.AddWithValue("@CustomerID", CustomerID)
cmd.Parameters.AddWithValue("@CustomerName", CustomerName)
cmd.Parameters.AddWithValue("@CustomerPhoto", SqlDbType.Image).Value = photo
cmd.Parameters.AddWithValue("@CustomerEmail", CustomerEmail)
cmd.Parameters.AddWithValue("@CustomerPhone1", CustomerPhone1)
cmd.Parameters.AddWithValue("@CustomerPhone2", CustomerPhone2)
cmd.Parameters.AddWithValue("@CustomerAddress", CustomerAddress)
cmd.Parameters.AddWithValue("@CustomerFax", CustomerFax)
cmd.Parameters.AddWithValue("@CustomerStatus", CustomerStatus)
cmd.Parameters.AddWithValue("@CountryID", CountryID)
cmd.Parameters.AddWithValue("@CityID", CityID)
cmd.Parameters.AddWithValue("@Notes", Notes)
cmd.Parameters.AddWithValue("@ModifiedBy", ModifiedBy)
retval = dm.executeNonQuery(cmd)
Return retval
End Function
业务层类代码:
Public Function Update_Customer_WithOutPic(ByVal CustomerID As String, ByVal CustomerName As String, ByVal CustomerEmail As String, ByVal CustomerPhone1 As String, ByVal CustomerPhone2 As String, ByVal CustomerAddress As String, ByVal CustomerFax As String, ByVal CustomerStatus As Boolean, ByVal CountryID As Integer, ByVal CityID As Integer, ByVal Notes As String, ByVal ModifiedBy As String) As String
Dim retval As String
retval = p.Update_Customer_WithOutPic(CustomerID, CustomerName, CustomerEmail, CustomerPhone1, CustomerPhone2, CustomerAddress, CustomerFax, CustomerStatus, CountryID, CityID, Notes, ModifiedBy)
Return retval
End Function
更新按钮代码:
Dim retval As String = p.Update_Customer(txtCustomerCode.Text, txtCustomerName.Text, txtCustomerEmail.Text, txtCustomerPhone1.Text, txtCustomerPhone2.Text, txtCustomerAddress.Text, txtCustomerFax.Text, CheckBox2.Checked, ComboCustomerCountry.SelectedValue, ComboCustomerCity.SelectedValue, txtCustomernote.Text, FrmMain.LblUserID.Text)
错误:
过程或函数'Update_Customer'需要参数'@CustomerPhoto',但未提供。
答案 0 :(得分:0)
在Update_Customer()
函数中,您需要为photo
数组提供Byte()
的值。
Class Test
Sub Save(connectionString As String, photoFilePath As String)
Dim photo As Byte() = GetPhoto(photoFilePath)
Using connection As SqlConnection = New SqlConnection(connectionString)
Using command As New SqlCommand(
"INSERT INTO Employees (Photo) Values (@Photo)", connection)
command.Parameters.Add("@Photo", SqlDbType.Image, photo.Length).Value = photo
connection.Open()
command.ExecuteNonQuery()
End Using
End Using
End Sub
Public Shared Function GetPhoto(filePath As String) As Byte()
Dim photo As Byte()
Using stream As New FileStream(filePath, FileMode.Open, FileAccess.Read)
Using reader As New BinaryReader(stream)
photo = reader.ReadBytes(stream.Length)
End Using
End Using
Return photo
End Function
End Class