Need help to fix a database entry Bug in Access from VB.net Form
Posted on 2006-07-19
Hey whats up guys how is everyone doing on this HOT HOT HOT Summer day lol.
Anyhow I'm facing a bug with my VB form inserting data into Access.
Ok here is the scoop.
First and foremost so far I'm trying to enter data only using 2 label values (FirstName, MiddleName) into my Access database.
Now here is the tricky part
when I enter data for the first time Everything is cool.
Now the 2nd time I decide to enter data the new data is not inserted.
BUT if I decide to wipe out the first data I inserted (goind into access and clicking on the row and deleting the data ) and then try again the new data gets inserted with no problem.
So far I can say is this
I have a primary key in the table within access that uses an AUTO number by access to give me an ID.
so in that case I don't need my user to put in an ID key , Access takes care of it for me :)
Everytime I decide to put in extra data (in other words new names etc) the program runs a bit slow and then it gives me a save messagebox,...but it really doesnt save at all.
But again if I go back to access and delete the whole row and try it again..it saves perfectly.
What could be the problem guys!?!?
Here is my little rookie code...tell me what you guys think?
Dim FirstName = LabelFirstName.Text
Dim MiddleName = LabelMiddleName.Text
Dim connString As String = " Provider =Microsoft.JET.OLEDB.4.0; Data Source =X:\members.mdb;"
Dim myConnection As OleDbConnection = New OleDbConnection
Dim InsertCMD As OleDbCommand = New OleDbCommand
myConnection.ConnectionString = connString
.Connection = myConnection
.CommandText = "Insert INTO [PrintTable](FirstName,MiddleName)" & _
" Values (@FirstName,@MiddleName) "
.CommandType = CommandType.Text
.Parameters.Add(New OleDbParameter("@FirstName", OleDbType.Char, 30))
.Parameters.Add(New OleDbParameter("@MiddleName", OleDbType.Char, 30))
.Parameters("@FirstName").Value = FirstName
.Parameters("@MiddleName").Value = MiddleName
Catch OleDbExceptionErr As OleDbException
Catch InvalidOperationExceptionErr As InvalidOperationException
If myConnection.State <> ConnectionState.Closed Then myConnection.Close()
MessageBox.Show("Form is now Saved!!)