please help!!!me..

I'm a beginner vb.net programmer

I have a difficult that is how can I save image file from vb.net to sql server

Recommended Answers

All 5 Replies

Private Sub myPicture()
Dim SqlString As String = ""
Dim fs As FileStream
Dim imagedata() As Byte

fs = New FileStream(Me.PictureBox1.ImageLocation, FileMode.Open)
ReDim imagedata(fs.Length)
fs.Read(Me.imagedata, 0, fs.Length)
fs.Close()

Dim para As New List(Of SqlParameter)

SqlString = "update PartyEmpMaster set EmpImage=@img where Name='" & Me.txtEmployeeName.Text.Trim & "'"
para.Add(New SqlParameter("@img", Me.imagedata))

RasClass.addnewrecord(SqlString, para)
End Sub

Private Sub myPicture()
Dim SqlString As String = ""
Dim fs As FileStream
Dim imagedata() As Byte
dim conn As New SqlConnection(SqlConnString)
Dim command As New SqlCommand()


fs = New FileStream(Me.PictureBox1.ImageLocation, FileMode.Open)
ReDim imagedata(fs.Length)
fs.Read(Me.imagedata, 0, fs.Length)
fs.Close()

Dim cpara As New List(Of SqlParameter)

SqlString = "update PartyEmpMaster set EmpImage=@img where Name='" & Me.txtEmployeeName.Text.Trim & "'"
cpara.Add(New SqlParameter("@img", Me.imagedata))

conn.Open()
command.Connection = conn
command.CommandText = sqlstring
command.Parameters.AddRange(cpara.ToArray)
command.ExecuteNonQuery()
conn.Close()

End Sub

From Anil Sutariya

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.