12 Replies - 5791 Views - Last Post: 30 August 2013 - 11:13 PM Rate Topic: -----

#1 onlyshiv  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 14
  • Joined: 04-April 12

storing and retrieving image from mysql database using vb 10

Posted 06 July 2012 - 07:40 AM

I have prepared a database and I want to show image in my vb form
for e.g.
For Employee detail I want to show employee image in the form and same want to store in database so that if anytime I want to view the employee detail then the image of that particular employee should be shown....
I have used the picture box in my form but don't know how to store it in my database....
Any help will be appreciated... Thanks in advance!!

Is This A Good Question/Topic? 0
  • +

Replies To: storing and retrieving image from mysql database using vb 10

#2 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 9055
  • View blog
  • Posts: 33,988
  • Joined: 12-June 08

Re: storing and retrieving image from mysql database using vb 10

Posted 06 July 2012 - 07:46 AM

Convert it to a binary array and store it as a "varbinary(max)". Here's a snippet that outlines that.

http://www.dreaminco...snippet6253.htm
Was This Post Helpful? 0
  • +
  • -

#3 onlyshiv  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 14
  • Joined: 04-April 12

Re: storing and retrieving image from mysql database using vb 10

Posted 06 July 2012 - 07:53 AM

View Postmodi123_1, on 06 July 2012 - 07:46 AM, said:

Convert it to a binary array and store it as a "varbinary(max)". Here's a snippet that outlines that.

http://www.dreaminco...snippet6253.htm

Thanks for instance reply...
Let me try...
Was This Post Helpful? 0
  • +
  • -

#4 onlyshiv  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 14
  • Joined: 04-April 12

Re: storing and retrieving image from mysql database using vb 10

Posted 06 July 2012 - 08:05 AM

View Postmodi123_1, on 06 July 2012 - 07:46 AM, said:

Convert it to a binary array and store it as a "varbinary(max)". Here's a snippet that outlines that.

http://www.dreaminco...snippet6253.htm

Can you please give me the code to it in the database
I am getting error..
Was This Post Helpful? 0
  • +
  • -

#5 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 9055
  • View blog
  • Posts: 33,988
  • Joined: 12-June 08

Re: storing and retrieving image from mysql database using vb 10

Posted 06 July 2012 - 08:11 AM

That is the code.

I have no idea what error you are getting so I cannot help you fix it.

No.. we do not just hand out code here, but instead expect you to learn and do the heavy lifting yourself. If you are looking for handouts - well.. it might be best to hit the dusty trail. If you are looking to learn then provide more information.
Was This Post Helpful? 0
  • +
  • -

#6 onlyshiv  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 14
  • Joined: 04-April 12

Re: storing and retrieving image from mysql database using vb 10

Posted 06 July 2012 - 08:23 AM

View Postmodi123_1, on 06 July 2012 - 08:11 AM, said:

That is the code.

I have no idea what error you are getting so I cannot help you fix it.

No.. we do not just hand out code here, but instead expect you to learn and do the heavy lifting yourself. If you are looking for handouts - well.. it might be best to hit the dusty trail. If you are looking to learn then provide more information.

Dim myByteArray() As Byte = Nothing

        Dim sLocation As String = "F:\sk.jpg"
        Dim oFileStream As New FileStream(sLocation, FileMode.Open)

        Try
            myByteArray = New Byte(oFileStream.Length - 1) {}
            oFileStream.Position = 0
            oFileStream.Read(myByteArray, 0, oFileStream.Length - 1)
        Catch ex As Exception
            MsgBox(ex.Message)
        Finally
            oFileStream.Dispose()
        End Try
        connection.Open()
        Dim cmd As New MySqlCommand
        cmd.Connection = connection
        cmd.CommandText = "INSERT INTO pament_detail(image) value(myByteArray)"
        cmd.ExecuteNonQuery()
        connection.Close()


here what I did....
Was This Post Helpful? 0
  • +
  • -

#7 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 9055
  • View blog
  • Posts: 33,988
  • Joined: 12-June 08

Re: storing and retrieving image from mysql database using vb 10

Posted 06 July 2012 - 08:24 AM

Okay - better.. so what's the error? what line is it on? You know - the pertinent information that is great for helping out errors!
Was This Post Helpful? 0
  • +
  • -

#8 onlyshiv  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 14
  • Joined: 04-April 12

Re: storing and retrieving image from mysql database using vb 10

Posted 06 July 2012 - 08:27 AM

View Postmodi123_1, on 06 July 2012 - 08:24 AM, said:

Okay - better.. so what's the error? what line is it on? You know - the pertinent information that is great for helping out errors!

yes I know...
I'm not getting anything inserted in my database... and it is not showing any the pertinent information
that y...
Was This Post Helpful? 0
  • +
  • -

#9 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 9055
  • View blog
  • Posts: 33,988
  • Joined: 12-June 08

Re: storing and retrieving image from mysql database using vb 10

Posted 06 July 2012 - 08:32 AM

You said you were getting an error.. so that was erroneous information?

cmd.CommandText = "INSERT INTO pament_detail(image) value(myByteArray)"

What are you doing with this line? Use parameters in place of the "myByteArray".
Was This Post Helpful? 0
  • +
  • -

#10 onlyshiv  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 14
  • Joined: 04-April 12

Re: storing and retrieving image from mysql database using vb 10

Posted 06 July 2012 - 08:35 AM

Actually I am new to vb...
can you please elaborate - which parameter
Was This Post Helpful? 0
  • +
  • -

#11 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 9055
  • View blog
  • Posts: 33,988
  • Joined: 12-June 08

Re: storing and retrieving image from mysql database using vb 10

Posted 06 July 2012 - 08:40 AM

When sql reads this line:
cmd.CommandText = "INSERT INTO pament_detail(image) value(myByteArray)"

it things "myByteArray" is a column name in it's table.. or some sort of SQL variable... you are not making the jump from your VB.NET code and the values of the variable "myByteArray" there to something SQL and can use. What you need are parameters. They are place holders in your SQL query that fill with data... your command object knows when you specify parameter named X and it's data Y on the VB.NET side - it fills in the parameter bit of the SQL (right before it tries to execute the SQL) and essentially replaces the bit of string X with the value you provided in Y.

https://dev.mysql.co...mand-parameters
Was This Post Helpful? 1
  • +
  • -

#12 onlyshiv  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 14
  • Joined: 04-April 12

Re: storing and retrieving image from mysql database using vb 10

Posted 06 July 2012 - 08:45 AM

thanks a lot!!!
For such a nice explanation...
And I got the solution...
Th
Was This Post Helpful? 0
  • +
  • -

#13 shashikumar s.g  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 30-August 13

Re: storing and retrieving image from mysql database using vb 10

Posted 30 August 2013 - 11:13 PM

i am also facing same problem can u show the code which give the solution to u
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1