vincent mapalala

vincent mapalala

  • NA
  • 13
  • 13.4k

how to retrieve picture stored in sqlserver2000 database using windows form(vb2005)

Nov 17 2010 6:34 AM

an image stored in field picture,table name is info

 

am usind below codes but am getting errors

and iwant show the path on txtpics textbox control

 

myconnection = New SqlConnection("server=(local);Initial Catalog=stock;Integrated Security=SSPI")

 

        myconnection.Open()

        mycommand = New SqlCommand("select cartype,eng,color,price,year,extras,picture,carname from info where sno='" + txtsno.Text + "'", myconnection)

        dr = mycommand.ExecuteReader

        While dr.Read()

            txttype.Text = dr("cartype").ToString()

            txteng.Text = dr("eng").ToString()

            txtcolor.Text = dr("color").ToString()

            txtcarname.Text = dr("carname").ToString()

            txtprice.Text = dr("price").ToString()

            txtyear.Text = dr("year").ToString()

            txtextras.Text = dr("extras").ToString()

txtpics.Text = dr("picture").ToString()

                       

        End While

        dr.Close()

        Dim da As New System.Data.SqlClient.SqlDataAdapter(mycommand)

        Dim ds As New DataSet()

        da.Fill(ds)

 

        Dim bits As Byte() = CType(ds.Tables("info").Rows(0)("picture"), Byte())

        Dim memorybits As New IO.MemoryStream(bits)

        Dim bitmap As New Bitmap(memorybits)

        PictureBox1.Image = bitmap

        myconnection.Close()


Answers (5)