[RESOLVED] Updating Database Data
I am working on a project that stores data on animals. I am trying to make updates to data already stored there, through inputs on a VB form.
A form where all the data is populating the fields shows up and the user can change/update any field. Once they are finished, they click update and the DB is supposed to reflect those changes (Theoretically)
However, I wrote the code to do that, but when it runs nothing in the database is changed and nothing gets done, as it seems. No errors appear and nothing goes wrong with the program. It just doesnt change the data in the db.
any suggestions on what to do?
Here is the code updating the database.
Code:
If txtNewID.Text = "" Or cmbRegion.Text = "" Or txtWombatName.Text = "" Or cmbGender.Text = "" Or txtAge.Text = "" Or txtWeight.Text = "" Or txtLength.Text = "" Or txtCommunity.Text = "" Or txtDescription.Text = "" Then
MsgBox("Please fill in all required fields.", , "ERROR")
Else
'Updates data
Dim addCommand As New OleDbCommand
addCommand.Connection = staffConnection
addCommand.CommandText = "UPDATE wombat_data SET wombat_name ='" & txtWombatName.Text & "', region ='" & cmbRegion.Text & "', gender = '" & cmbGender.Text & "', age ='" & txtAge.Text & "', weight = '" & txtWeight.Text & "', length = '" & txtLength.Text & "', sample_description ='" & cmbSample.Text & "', community_name ='" & txtCommunity.Text & "', description ='" & txtDescription.Text & "' WHERE wombat_id =" & txtNewID.Text
Dim updateInfo As Integer = addCommand.ExecuteNonQuery()
MsgBox("Wombat data has been modified.")
End If
Re: [help] Updating Database Data
What's the return value of ExecuteNonQuery? It should indicate a count of affected rows. What's the value of txtNewID.Text in your where clause? Is it a valid id? Does a record definitely exist with that id?
I would check these & copy the update syntax into SQL Management Studio & run it to see what happens.
Re: [help] Updating Database Data
value returned by the executenonquery was = 1
the value of txtNewID.Text is a # that was previously assigned to it. there will always be a record associated with an id. the Id is selected from a combo box which is populated from the database using a datareader.
Re: [help] Updating Database Data
it works now. dunno how i did it. thanks for the response !