Hi guys!
I'm using an openfiledialog along with some other textboxes and so and then extracting the text from the textboxes and putting them into my database. When I open a file with the dialog I also take the path to the file and put it in to a textbox to save it later in the database. But this is where it all goes wrong, it works fine to save if I don't import a picture, but once I import a picture (it goes in a picture box for preview and path in the textbox) then when I add the stuff to the database it changes the path to the database, replacing it with the path to the image? :S
And I just can't figure out why! I've tried everything, I tried writing the path to a textfile instead, same error, even when that code is outside the db-connection.
Even if I don't put in any code relating to saving the image in the database or anywhere else I still get the same error as long as I import an image to my picturebox!
I really need help!
Here's the code for importing the image, and saving it to my database:
vb Code:
Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click With OpenFileDialog1.Filter = "All Images (*.gif; *.jpeg; *.jpg; *.bmp)|*.gif; *.jpeg; *.jpg; *.bmp" End With If OpenFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then PictureBox3.SizeMode = PictureBoxSizeMode.StretchImage PictureBox3.ImageLocation = OpenFileDialog1.FileName BrowseText.Text = OpenFileDialog1.FileName End If End Sub
vb Code:
Private Sub AddMovieBtn_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AddMovieBtn.Click Dim addresponce As Integer addresponce = MsgBox(" Do you want to add the following object? " + "Movie Title: " + Title.Text, MsgBoxStyle.YesNo) If addresponce = vbYes Then If Title.Text = "" And Actor.Text = "" And Descrip.Text = "" And Length.Text = "" Then MsgBox("You have to fill at least 1 field!") Else If Rating.Text = "" Then Rating.Text = "1" End If If Length.Text = "" Then Length.Text = "1" End If Try cn = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=movies.mdb;") cn.Open() str = "INSERT INTO moviedata (Title, Length, Actors, Description, Rating, Genre, Location, ImageLocation) VALUES('" & Title.Text & "' , '" & Length.Text & "' , '" & Actor.Text & "' , '" & Descrip.Text & "' , '" & Rating.SelectedItem & "' , '" & Genre.SelectedItem & " ' , '" & FileLocation.Text & "', '" & BrowseText.Text & "')" cmd = New OleDbCommand(str, cn) icount = cmd.ExecuteNonQuery 'MsgBox(icount) 'displays number of records inserted cn.Close() MsgBox("The Movie Has Been Added To The Database") 'Rensa ut all data Title.Text = "" Length.Text = "" Actor.Text = "" Descrip.Text = "" Rating.Text = "" Genre.Text = "" FileLocation.Text = "" BrowseText.Text = "" PictureBox3.Image = Nothing Catch ex As Exception MessageBox.Show(ex.ToString()) 'Catch ' MsgBox("An error was reported! Please try again!") End Try End If Else If addresponce = vbNo Then Me.Select() End If End If Me.MoviedataTableAdapter.Fill(Me.MoviesDataSet.moviedata) End Sub




Reply With Quote