[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 270
  • Last Modified:

What is this error telling me I am doing wrong.

I am using this code in a script that uploads files to an SQL 2008 server. It produces an error that I can not figure out. What is this error telling me I am doing wrong. As far as I know I am passing these values in my script.

ERROR
The parameterized query '(@fileData varbinary(max) ,
@fileGuid uniqueidentifier,
@fileName ' expects the parameter '@fileData',
 which was not supplied.

SCRIPT
    Const SQL_INSERT As String = "INSERT INTO [imageFile] ([fileGuid],[fileName],[fileData],[fileId])" & _
                                                  "values (@fileGuid, @fileName, @fileData); select @fileId = SCOPE_IDENTITY()"

               cmdInsert.Parameters.Add("@fileData", SqlDbType.VarBinary, -1)

                cmdInsert.Parameters.Add("@fileGuid", SqlDbType.UniqueIdentifier)
                cmdInsert.Parameters("@fileGuid").Value = file.fileGuid

                cmdInsert.Parameters.Add("@fileName", SqlDbType.VarChar, 256)
                cmdInsert.Parameters("@fileName").Value = file.newFileName

                cmdInsert.Parameters.Add("@fileId", SqlDbType.BigInt)
                cmdInsert.Parameters("@fileId").Direction = ParameterDirection.Output
0
ruffone
Asked:
ruffone
1 Solution
 
knightEknightCommented:
at first glance it looks like you are specifying 4 columns in the insert list, but only 3 values:

INSERT INTO [imageFile] ([fileGuid], [fileName], [fileData], [fileId])" & _
                            "values (@fileGuid, @fileName, @fileData)
0
 
BuggyCoderCommented:
assign a value to @filedata parameter like this:-

  cmdInsert.Parameters("@fileData").Value = <SomeFileBinaryData>
0
 
ruffoneAuthor Commented:
If I must use a value I only want to pass a single byte(). How do I assign a single byte()
0
Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

 
adriankohwsCommented:
So long your codes behind changed the data into binary, it doesn't matter so long it doesn't exceed the maximum size allowed.
0
 
CodeCruiserCommented:
Try changing

 cmdInsert.Parameters.Add("@fileData", SqlDbType.VarBinary, -1)

to

 cmdInsert.Parameters.Add("@fileData", SqlDbType.VarBinary, System.Text.Encoding.ASCII.GetBytes(" "))
0
 
ruffoneAuthor Commented:
This is a project that I am moving from my VS10 development environment into VS11 Beta DE. while tweaking my classes. I did not figure out what caused the error but when I reimported my bits from VS10 into VS11 and made my changes incrementally I did not end up with the error. Thank you all for your responses
0
 
ruffoneAuthor Commented:
I figured out that the upload process fails when I check "IsImage". When I comment that line then the the process completes successfully I have no ides why this happens


    If filePath.InputStream.Length > -1 Then
        _fileData = filePath.InputStream
        If IsImage(_fileData) = False Then
            Exit Sub
        End If
        ...
    End If

    Private Function IsImage(file As Stream) As Boolean
        Using bitmap As New Bitmap(file, False)
            If bitmap.RawFormat.Equals(ImageFormat.Bmp) Then
                Return True
                Exit Function
            End If
            If bitmap.RawFormat.Equals(ImageFormat.Jpeg) Then
                Return True
                Exit Function
            End If
            If bitmap.RawFormat.Equals(ImageFormat.Gif) Then
                Return True
                Exit Function
            End If
            If bitmap.RawFormat.Equals(ImageFormat.Png) Then
                Return True
                Exit Function
            End If
            If bitmap.RawFormat.Equals(ImageFormat.Tiff) Then
                Return True
                Exit Function
            End If
            If bitmap.RawFormat.Equals(ImageFormat.Icon) Then
                Return True
                Exit Function
            End If

            Return False
        End Using
    End Function
0
 
ruffoneAuthor Commented:
0
 
ruffoneAuthor Commented:
Thanks guys
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now