2017-04-09 50 views
1

予客户表的更新期间,有这样的错误:需要参数“@CustomerPhoto”,但未提供

过程或函数“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',但未提供。

+1

**错误是明显的**:你是不是在传递参数值,'@ CustomerPhoto'。 – Wanderer

+0

其在这里cmd.Parameters.AddWithValue(“@ CustomerPhoto”,SqlDbType.Image).Value = photo – Salem

+0

欢迎来到StackOverflow!你的问题很好,并遵循[如何问]的规则(http://stackoverflow.com/help/how-to-ask)。不过,您的标题可能会有所改进。 +1 – InteXX

回答

0

在您的Update_Customer()函数中,您需要为photo提供一个值,作为Byte()数组。

下面是来自MSDN documentation转述例如:

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 
相关问题