problem updating access database using visual basic

Discussion in 'Visual Basic ( VB )' started by VIKAS1111, Feb 25, 2008.

  1. VIKAS1111

    VIKAS1111 New Member

    Joined:
    Feb 23, 2008
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    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 ????
     
    Last edited by a moderator: Feb 25, 2008
  2. KiLLER

    KiLLER New Member

    Joined:
    Mar 2, 2008
    Messages:
    6
    Likes Received:
    0
    Trophy Points:
    0
    Are you trying to add data or edit something what's already in there :s???

    If you're adding data then... you need to move your pointer to last and then Add new record

    Code:
    rsnew3.MoveLast
    rsnew3.Add
    
    and then you can add everything you want to... and then rsnew3.update :)
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice