954,514 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Buffer cannot be null. Parameter name: buffer

Sub retrievepic()

        Dim conn As New SqlConnection("data source=.\sqlexpress; integrated security=true; attachdbfilename=|datadirectory|\WAIS.mdf; user instance=true;")
        Dim cmd As New SqlCommand("select ImageData from ImagesStore where ImageId=@ImageId", conn)

        cmd.Parameters.AddWithValue("@ImageId", 3)

        Try
            conn.Open()
            PictureBox1.Image = Image.FromStream(New IO.MemoryStream(CType(cmd.ExecuteScalar, Byte())))
        Catch ex As Exception
            MsgBox(ex.Message)
        Finally
            conn.Close()
        End Try
    End Sub


This is my code for retrieving pictures, it was working before but then i accidentally deleted the table and i created it again with the same name and same fields. and now whenever i open the form with the picture, there was a message box error. it says

Buffer cannot be null. Parameter name: buffer

I don't know what i did wrong.

aishapot
Junior Poster in Training
75 posts since Sep 2011
Reputation Points: 7
Solved Threads: 0
 

Are the field types consistent with the code?

catherine sea
Junior Poster
126 posts since Jan 2008
Reputation Points: 25
Solved Threads: 20
 

Yes.

aishapot
Junior Poster in Training
75 posts since Sep 2011
Reputation Points: 7
Solved Threads: 0
 


Are you still fighting this?

There are only two possible choices. You do not have an ImageId = 3 or the row with ImageId = 3 has a null value for column ImageData.

Fix it and move on with your life.

Unhnd_Exception
Posting Pro
570 posts since Nov 2010
Reputation Points: 249
Solved Threads: 201
 

Yes I'm still 'fighting' it. because everytime i drop and recreate the table, i have to not call the retrievepic function first and then recall it for it to work.
i'm sure the pictures are storing, i check it everytime i insert a student.

aishapot
Junior Poster in Training
75 posts since Sep 2011
Reputation Points: 7
Solved Threads: 0
 

i want to know why it's happening. when i'm pretty sure that the image is adding in the database

aishapot
Junior Poster in Training
75 posts since Sep 2011
Reputation Points: 7
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: