error updating access database using visual basic
hi everybody
i am trying to access a database and update the changes..
Here is the code...
Code:
Option Explicit
Dim c As New adodb.Connection
Dim cn As New adodb.Connection
Dim cm As adodb.Command
Dim rsnew2 As New adodb.Recordset
Dim rsnew3 As New adodb.Recordset
Private Sub cmd_close_Click()
Unload.me
End Sub
Private Sub cmd_edit_Click()
rsnew3.Open "select * from company", c, adOpenDynamic, adLockOptimistic
If text1.Text = "" Then
MsgBox " enter the company name"
text1.SetFocus
rsnew3.Fields("text1") = text1.Text
End If
If text2.Text = "" Then
MsgBox " enter the company address"
text2.SetFocus
rsnew3.Fields("text2") = text2.Text
End If
rsnew3.Update
MsgBox " add new successful ", vbInformation, "successful"
End Sub
Private Sub Form_Load()
Dim cs As String
c.Open ("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\COMION.MDB;Persist Security Info=False")
rsnew2.Open "select * from company", c, adOpenDynamic
Me.text1.Text = rsnew2(2)
Me.text2.Text = rsnew2(3)
End Sub
I am getting message that "edit is successful", but its not updating in database..
What should i do ????
Re: error updating access database using visual basic
Quote:
I am getting message that "edit is successful", but its not updating in database..
What should i do ????
Hi,
I don't see you closing the database connection, just closing you're app. I think the data is only actually written when the database is properly closed, but could be way of line. I don't know that much about databases. :)
HTH
Re: error updating access database using visual basic
Open up your database.
Are the records there?
Re: error updating access database using visual basic
Ya data are there in database and i even tried closing record set .. But no difference
Re: error updating access database using visual basic
Quote:
Originally Posted by vikas1111
Ya data are there in database
So, they are in the database, which means that this
Quote:
Originally Posted by vikas1111
but its not updating in database..
really isn't true.
As such, what is the issue that you need to address?
Re: error updating access database using visual basic
Quote:
Originally Posted by vikas1111
Private Sub cmd_edit_Click()
rsnew3.Open "select * from company", c, adOpenDynamic, adLockOptimistic
'If "Text1.text" is a null string ????, then fields "Text1" = empty
If text1.Text = "" Then
MsgBox " enter the company name"
text1.SetFocus
rsnew3.Fields("text1") = text1.Text
End If
'If "Text2.text" is a null string ????, then fields "Text2" = empty
If text2.Text = "" Then
MsgBox " enter the company address"
text2.SetFocus
rsnew3.Fields("text2") = text2.Text
End If
rsnew3.Update
MsgBox " add new successful ", vbInformation, "successful"
End Sub
I think it won't update any field, if the msgbox " add new successfull " shown...
Try this code :
Code:
Private Sub cmd_edit_Click()
rsnew3.Open "select * from company", c, adOpenDynamic, adLockOptimistic
If text1.Text = "" Then
MsgBox " enter the company name"
Text1.SetFocus
End If
If text2.Text = "" Then
MsgBox " enter the company address"
Text2.SetFocus
End If
rsnew3.Fields("text2") = text2.Text
rsnew3.Fields("text1") = text1.Text
rsnew3.Update
MsgBox " add new successful ", vbInformation, "successful"
End Sub
Re: error updating access database using visual basic
Probably the fact that all that's being done is the FIRST record is being updated.... no new records are being added. The recordset is being opened and the fields Text1 and Text2 are being updated..... and that's it... mean while, you should be doing your data checks BEFORE you open the data.... doing them inline like that will cause problems in the long run.
-tg
Re: error updating access database using visual basic
Quote:
Originally Posted by Hack
So, they are in the database, which means that thisreally isn't true.
As such, what is the issue that you need to address?
Fine .. I am accessing data which are already stored in the database.. I need to access them and update..and save the changes made to the accessed data.. The error in the program is , i am getting message "Update successful " but once i open database and see, the records are same as earlier , no updation takes place...