3
Reply

hi guys, plse plse help me to retieve image stored in sqldb field name is picture, my code is below, am student learning visuel studio.net

vincent mapalala

vincent mapalala

Nov 16 2010 4:17 AM
8.3k



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()

iwant to display image stored in picture field  bt am gettinf error, plse help me to do this


Answers (3)