预计参数'@customerphoto',未提供 [英] Expects parameter '@customerphoto', which was not supplied

查看:68
本文介绍了预计参数'@customerphoto',未提供的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

< pre>我在更新customer表时遇到此错误:

过程或函数'Update_Customer'需要参数'@CustomerPhoto',这是未提供的。

存储过程代码:< pre>





  ALTER   procedure  [dbo]。[Update_Customer] 
@ CustomerID int 输出
@客户名称 nvarchar 50 ),
@CustomerPhoto image
@ CustomerEmail nvarchar (Max),
@ CustomerPhone1 nvarchar (< span class =code-digit> 12 ),
@ CustomerPhone2 nvarchar 12 ),
@ CustomerAddress nvarchar (Max),
@ CustomerFax nvarchar 12 ),
@CustomerStatus 位<​​/ span>,
@ CountryID int
@ CityID int
@Notes nvarchar (Max),
@ ModifiedBy nvarchar 30
AS
BEGIN
更新 CustomersTbl
SET CustomerID = @ C ustomerID
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





数据层类代码:





 朋友 功能 Update_Customer( ByVal  CustomerID  As   String ,< span class =code-keyword> ByVal  CustomerName 作为 字符串 ByVal  CustomerEmail 作为 字符串 ByVal  CustomerPhone1 作为 字符串 ByVal  CustomerPhone2  As  字符串 ByVal  CustomerAddress  As  字符串 ByVal  CustomerFax 作为 字符串 ByVal  CustomerStatus 作为 布尔值 ByVal  CountryID 作为 整数 ByVal  CityID 作为 整数,< span class =code-keyword> ByVal 注释作为 字符串 ByVal  ModifiedBy  As   String 作为  String  
Dim retval As String

Dim cmd As < span class =code-keyword>新 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)

返回 retval
结束 功能







业务层类代码:



 公共 函数 Update_Customer_WithOutPic( ByVal  CustomerID 作为 字符串 ByVal  CustomerName 作为 字符串 ByVal  CustomerEmail 作为 字符串 ByVal  CustomerPhone1 作为 字符串 ByVal  CustomerPhone2 作为 字符串 ByVal  CustomerAddress 作为 字符串 ByVal  CustomerFax 正如 字符串 ByVal  CustomerStatus  As  布尔 ByVal  CountryID 作为 < span class =code-keyword>整数, ByVal  CityID 作为 整数 ByVal 备注作为 字符串 ByVal  ModifiedBy 作为 字符串 As  字符串 
Dim retval As 字符串
retval = p.Update_Customer_WithOutPic(CustomerID,CustomerName,CustomerEmail,CustomerPhone1,CustomerPhone2,CustomerAddress,CustomerFax,CustomerStatus ,CountryID,CityID,Notes,ModifiedBy)
返回 retval
结束 功能





更新按钮代码:



  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)





模块:

 公共 功能 GetPhoto( ByVal  filePath  As   String 作为 字节()
Dim stream As FileStream = FileStream(filePath,FileMode.Open,FileAccess.Read )
Dim reader As BinaryReader = New BinaryReader(stream)
Dim photo() As Byte = reader.ReadBytes(stream.Length)
reader.Close()
stream.Close ()
返回照片
结束 函数


公共 函数 byteArrayToImage( ByVal byt As Byte ())< span class =code-keyword> As Image
Dim ms As System.IO.MemoryStream()
Dim drwimg As Image = Nothing
尝试
ms.Write (byt, 0 ,byt.Length)
drwimg = 位图(ms)
最后
ms.Close()
结束 尝试
返回 drwimg
结束 功能





我尝试了什么:



我确定图片框不是空的

Update_Customer - 因为你没有将值作为方法参数传递。

如果它为空 - 我敢打赌它是 - 你会得到那个错误,最好把它作为参数传递函数而不是依赖于类级别变量。


在您的存储过程中,所有字段都是必填字段。



这类问题o然后确定您通过SP从应用程序传递到DB的某些参数为空。

如果您认为@CustomerPhoto不应为null,请在调用SP之前进行空检查验证。



如果您认为某些参数可能包含值或不然后将此类型的参数设置为Null。

Ex:@CustomerPhoto image = null。


<pre>I have this error during update of the customer table:

Procedure or function 'Update_Customer' expects parameter '@CustomerPhoto', which was not supplied.

Stored procedure code :<pre>



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 



Data layer class code :


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




Business layer class code :

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



Update button code :

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)



Module :

Public Function GetPhoto(ByVal filePath As String) As Byte()
    Dim stream As FileStream = New FileStream(filePath, FileMode.Open, FileAccess.Read)
    Dim reader As BinaryReader = New BinaryReader(stream)
    Dim photo() As Byte = reader.ReadBytes(stream.Length)
    reader.Close()
    stream.Close()
    Return photo
End Function


Public Function byteArrayToImage(ByVal byt As Byte()) As Image
    Dim ms As New System.IO.MemoryStream()
    Dim drwimg As Image = Nothing
    Try
        ms.Write(byt, 0, byt.Length)
        drwimg = New Bitmap(ms)
    Finally
        ms.Close()
    End Try
    Return drwimg
End Function



What I have tried:

Iam sure that picture box is not empty

解决方案

Use the debugger and check what is in photo when you you get into Update_Customer - because you don't pass the value as a method parameter.
If it's null - and I bet it is - you would get that error, and be best off passing it as a parameter to the function instead of relying on a class level variable.


In your stored procedure all the fields are mandatory.

When this type of issue occurred then it is sure that some parameters which you are passing from application to DB through SP is null.
If you think @CustomerPhoto should not null then do the null check validation before calling the SP.

If you think some parameters may contains value or not then set this type of parameters as Null.
Ex: @CustomerPhoto image= null.


这篇关于预计参数'@customerphoto',未提供的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆