Results 1 to 8 of 8

Thread: <RESOLVED> help with adding data

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Sep 2004
    Posts
    20

    <RESOLVED> help with adding data

    I have created an odbc dsn connection with an access mdb
    i have all i want till now but i can't make the save button to save the
    data to the database. WHY WHY?? What am i doing wrong??



    Private Sub Command1_Click()
    Dim adoCN As ADODB.Connection
    Dim adoRS As ADODB.Recordset
    Dim strInsert As String


    Set adoCN = New ADODB.Connection

    With adoCN
    .ConnectionString = _
    "Provider=MSDASQL.1;" & _
    "Persist Security Info=False;" & _
    "Data Source=mystery"
    .Open
    Set adoRS = .Open("select * from mystery")
    End With

    If adoRS.State = adStateOpen Then adoRS.Close

    adoRS.CursorLocation = adUseServer
    adoRS.CursorType = adOpenKeyset
    adoRS.LockType = adLockOptimistic
    adoRS.Open "mystery", adoCN
    adoRS.AddNew ' add a new row

    adoRS("id") = txtid.Text
    adoRS("shop") = strshop
    adoRS("address") = straddress
    adoRS("area") = strarea
    adoRS("city") = strcity

    adoRS.Update
    adoRS.Close
    Set adoRS = Nothing
    adoCN.Close: Set adoCN = Nothing
    Last edited by tasan; Sep 16th, 2004 at 05:53 AM.

  2. #2
    PowerPoster Pasvorto's Avatar
    Join Date
    Oct 2002
    Location
    Minnesota, USA
    Posts
    2,951
    Set adoRS = new adodb.recordset

    not

    Set adoRS = .Open("select * from mystery")


    adoRS.Open "mystery", adoCN, adOpenKeyset, adlockoptimistic, adcmdtable

    adors.addnew
    ...
    ...

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Sep 2004
    Posts
    20
    I have made this changes as you said Pasvorto but i get an error trying to save in the line which is my primary key.

    adoRS("id") = txtid.Text

    Is there anything wrong about that cause what i do in my program is to open the Id field read the last record and then i add it +1 so not to
    double write the id field.

    The error message says:
    'RUN TIME ERROR - 2147217887'
    'ERRORS OCCURED'

    Any more advices or mistakes i 've done to the code??

  4. #4
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,174
    Is the ID field an autonumber?

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Sep 2004
    Posts
    20
    Yes, i tried what you are thinking...It works if i remove the id field .

    But why it doesn't work the way i thought it???

    Thanx a lot Pasvorto a real life saver you are...
    Last edited by tasan; Sep 16th, 2004 at 04:53 AM.

  6. #6
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,174
    Because it's an autonumber field. Your database decides what number goes in next, not you.

  7. #7

    Thread Starter
    Junior Member
    Join Date
    Sep 2004
    Posts
    20
    Ok mendhak you are right ... thanx for your advice !!

  8. #8
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,174
    Add [Resolved] to the thread title.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width