Private Sub btnsave_Click(sender As Object, e As EventArgs) Handles btnsave.Click
Dim com As New OleDbCommand()
' Try
Dim fs As New FileStream(str, FileMode.Open)
Dim data() As Byte = New [Byte](fs.Length) {}
fs.Read(data, 0, fs.Length)
fs.Close()
'readed image
Dim name As New OleDbParameter("namee", OleDbType.VarChar, 50)
name.Value = TextBox7.Text
Dim address As New OleDbParameter("address", OleDbType.VarChar, 50)
address.Value = TextBox8.Text
Dim contact As New OleDbParameter("contact", OleDbType.VarChar, 50)
contact.Value = TextBox9.Text
Dim dob As New OleDbParameter("dob", OleDbType.Date)
Dim s As String = DateTimePicker4.Text.Trim
Dim pattern As String = "MM/dd/yyyy"
Dim parsedDate As Date = Date.ParseExact(s, pattern, Nothing)
dob.Value = parsedDate
Dim entry_date As New OleDbParameter("entry_date", OleDbType.Date)
Dim a As String = DateTimePicker3.Text.Trim
Dim entry As Date = Date.ParseExact(a, pattern, Nothing)
entry_date.Value = entry
Dim salary As New OleDbParameter("salary", OleDbType.Integer)
salary.Value = Val(TextBox10.Text)
Dim img As New OleDbParameter("picture", OleDbType.Binary)
img.Value = data
'Adding parameters
com.Parameters.Add(name)
com.Parameters.Add(address)
com.Parameters.Add(contact)
com.Parameters.Add(dob)
com.Parameters.Add(entry_date)
com.Parameters.Add(salary)
com.Parameters.Add(img)
com.Connection = conn
com.CommandText = "insert into staff values(@name,@address,@contact,@dob,@entry_date,@salary,@img)"
com.ExecuteNonQuery()
MsgBox("Saved")
Me.StaffTableAdapter.Fill(Me.Database1DataSet.staff)
'Catch ex As Exception
'MsgBox(ex.Message)
'End Try
end sub
i am using this code to insert an images into access database. but when i click the button it gives me error that io exception unhandle...
Dim fs As New FileStream(str, FileMode.Open)
this is where i get erorr saying :
The process cannot access the file 'C:\Users\itechstore\Documents\sunil camera photo\2011-01-02 05.48.08.jpg' because it is being used by another process.
even those process is not been opened and i tried changing the directory but same error occured... i cant figure out the problem.. plz help me...
sushilsth 0 Light Poster
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.