help required for inserting fields with the help of ADODB

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • pramodrepaka
    New Member
    • Mar 2007
    • 21

    help required for inserting fields with the help of ADODB

    i am not able to add records with the help of ADODB. what is the problem i am not able to understand please help me. this is the code i written


    In General Declaration

    Dim cn As New ADODB.Connectio n
    Dim rs As New ADODB.Recordset

    Private Sub Form_Load()
    Set rs = New ADODB.Recordset
    rs.LockType = adLockBatchOpti mistic
    rs.CursorType = adOpenKeyset
    rs.ActiveConnec tion = cn
    rs.Source = "select * from t"
    rs.Open
    End sub


    Private Sub Command3_Click( )
    rs.addnew
    rs.Fields(0) = Text1.Text 'text1.text is character type data
    rs.Fields(1) = Val(Text2.Text) 'text2.text is number type data
    rs.Fields(2) = Val(Text3.Text) 'text3.text is number type data
    rs.Update
    End sub

    please solve my above code.
  • iburyak
    Recognized Expert Top Contributor
    • Nov 2006
    • 1016

    #2
    Change adOpenKeySet to adOpenDynamic.

    It is just a logical guess I didn't try it.

    adOpenKeySet has a static set of primary keys and you are trying to insert a new one.

    Hope it helps.

    Comment

    Working...