Click here to Skip to main content
15,894,343 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I need to store image as a Blob file in sql server 2005 using vb .net 2008. My cannection is Oledb.
Private Sub cmdsave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdsave.Click
          
        Dim fstream As FileStream
        Dim imgdata As Byte()
        Dim data As Byte()
        Dim finfo As FileInfo
        finfo = New FileInfo(txtpic.Text)
        Dim numbyte As Long
        Dim br As BinaryReader
        numbyte = finfo.Length
        fstream = New FileStream(txtpic.Text, FileMode.Open, FileAccess.Read)
        br = New BinaryReader(fstream)
        data = br.ReadBytes(numbyte)
        'MsgBox(data.ToString)
        imgdata = data

        If Not IsNumeric(txtmobile.Text) Then
            MsgBox("Mobile No should be numeric !!", MsgBoxStyle.Exclamation, "Uparjon HRM & Payroll")
            Exit Sub
        End If
        If sqlDT.Rows.Count > 0 Then
qlSTR = "INSERT INTO TBL_CompanyInf (BussName, BussNameB, BussLocation, BussLocationB, EstDate, BussContact, Tin, Email_Address, Website, logo) " & _
                     "VALUES ('" & txtcomp.Text & "', " _
                             & "'" & txtcompB.Text & "', " _
                             & "'" & txtloc.Text & "', " _
                             & "'" & txtlocB.Text & "', " _
                             & "'" & dtp1.Text & "', " _
                             & "'" & txtmobile.Text & "', " _
                             & "'" & txtfex.Text & "', " _
                             & "'" & txtemil.Text & "', " _
                             & "'" & txtweb.Text & "', " _
                             & "'" & txtpic.Text & "', " _
                            & "'" & imgdata(0) & "')"
            'MsgBox(sqlSTR)
            ExecuteSQLQuery(sqlSTR)
End sub 

now my need urgent help
Posted
Updated 26-Oct-13 3:35am
v2

Follow below link it discuss the same.

How to Store or Save Image in SQL Server table[^]
 
Share this answer
 
Please, do not concatenate strings to build a SQL command. It leaves you wide open to accidental or deliberate SQL Injection attack which can destroy your entire database. Use Parametrized queries instead.

That will also solve your problem.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900