Hi!
I'm trying to add some data from textboxes to my database. I had it working in another application using the same code just the other day. But no, niether the new app or the old is functioning. All I get is my error message, and the truth told, I'm not very good at error searching through my code.
Any help?
This is in the top of the main form.
And here is the sub that is my trouble.Code:Imports System.Text Imports System.Data.SqlClient Imports System.Data.OleDb Public Class StartForm Dim cn As OleDbConnection Dim cmd As OleDbCommand Dim dr As OleDbDataReader Dim icount As Integer Dim str As String
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 Try [B] cn = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=movies.mdb;") cn.Open() str = "INSERT INTO moviedata VALUES('" & Title.Text & "' , '" & Length.Text & "' , '" & Actor.Text & "' , '" & Descrip.Text & "' , '" & Rating.SelectedItem & "' , '" & Genre.SelectedItem & " ' , '" & FileLocation.Text & "')"[/B] 'string stores the command and CInt is used to convert number to string cmd = New OleDbCommand(str, cn) icount = cmd.ExecuteNonQuery 'MsgBox(icount) 'displays number of records inserted MsgBox("The Movie Has Been Added To The Database") 'Clear all data Title.Text = "" Length.Text = "" Actor.Text = "" Descrip.Text = "" Rating.Text = "" Genre.Text = "" FileLocation.Text = "" Catch MsgBox("An error was reported! Please try again!") End Try cn.Close() End If Else If addresponce = vbNo Then Me.Select() End If End If Me.MoviedataTableAdapter.Fill(Me.MoviesDataSet.moviedata) End Sub
Just one more quick question. When I use ComboBoxes, and I want the value I've choosen in it to go to the database. What should I select? Text, SelectedValue or SelectedItem?
Thanks for the help!




Reply With Quote