Click here to Skip to main content
15,887,776 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i got your solution and implement that also but still dint get it over.the error message i got is "incorrect syntax near @imagedata".
here's my code...plz assist me.......
-----------------------CODE--------------------------------
Collapse | Copy Code

Imports System
Imports System.Net
Imports System.Drawing
Imports System.Collections
Imports System.Componentmodel
Imports System.windows.Forms

Imports System.Data
Imports System.Runtime.InteropServices
Imports System.Drawing.Imaging
Imports System.IO

Imports System.Data.SqlClient
Imports System.IO.Directory
Imports System.Threading
Public Class scan_salary
Dim con As New SqlConnection(str)
Private Sub btn_browse_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_browse.Click
Try
OFD1.Filter = "Jpg Files(*.Jpg)|*.Jpg" & "|Jpeg Files(*.Jpeg)|*.Jpeg" & "|Gif Files(*.Gif)|*.Gif"
If OFD1.ShowDialog = Windows.Forms.DialogResult.OK Then
Label4.Text = OFD1.FileName
Else
Label4.Text = ""
End If

If Label4.Text = "" Then
PictureBox1.Visible = False
Else
lbl_path.Text = Label4.Text
Dim imgdata() As Byte = readfile(lbl_path.Text)
Dim ms As MemoryStream = New MemoryStream(imgdata, 0, imgdata.Length)
ms.Write(imgdata, 0, imgdata.Length)
Dim img As Image = Image.FromStream(ms, True)
PictureBox1.Image = img
End If
'PictureBox1.Image = Image.FromFile()

lbl_path.Text = Label4.Text
Label4.Text = Label4.Text.Remove(Label4.Text.LastIndexOf("\"))

Catch ex As Exception
MsgBox(ex.ToString())
End Try
End Sub

Public Function readfile(ByVal FPath As String) As Byte()
Dim data() As Byte
Try
Dim FI As New FileInfo(FPath)
Dim numbytes As Long = FI.Length
Dim fstream As FileStream = New FileStream(FPath, FileMode.Open, FileAccess.Read)
Dim br As BinaryReader = New BinaryReader(fstream)
data = br.ReadBytes(Convert.ToInt64(numbytes))
fstream.Close()
Catch ex As Exception
MsgBox(ex.Message.ToString)
End Try

Return data
End Function


Private Sub btn_save_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_save.Click
If con.State <> ConnectionState.Open Then
con.Open()


Dim insdate, effdate As String
insdate = Now().Date
effdate = dtp1.Value.ToString


Dim emp_id As String = Class2.Empid
Dim sal As String = Class2.salary

Dim imgdata() As Byte = readfile(lbl_path.Text)
Dim cmd As New SqlCommand("insert into emp.dbo.scan_salary ( emp_id,salary, imagedata, insert_date, effect_date)" & _
"values ( '" & emp_id & "', '" & sal & "', '" & insdate & "','" & effdate & "',@imagedata", con)
cmd.Parameters.Add(New SqlParameter("@imagedata", CType(imgdata, Object)))
'cmd.Parameters.Add(New SqlParameter("@insert_date", DateTime.Now.ToString("yyyy-MM-dd")))
'cmd.Parameters.Add(New SqlParameter("@effect_date", dtp1.Value.ToString("yyyy-MM-dd")))
'cmd.Parameters.Add(New SqlParameter("@emp_id", emp_id.ToString))
'cmd.Parameters.Add(New SqlParameter("@salary", sal.ToString.Trim))
'cmd1.Parameters.Add(New SqlParameter("@Docimage", CType(imgdata, Object)))
cmd.ExecuteNonQuery()
cmd.CommandTimeout = 0

End If
MsgBox("document uploaded")
End Sub
End Class
Posted
Comments
Sebastian T Xavier 29-Mar-12 1:04am    
Make your question more readable by displaying code in a code tag

1 solution

hi,

just add a " before @imagedata" and try....

C#
Dim cmd As New SqlCommand("insert into emp.dbo.scan_salary ( emp_id,salary, imagedata, insert_date, effect_date)" & _
"values ( '" & emp_id & "', '" & sal & "', '" & insdate & "','" & effdate & "',@imagedata", con)


Regards
 
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