Results 1 to 9 of 9

Thread: ADO Code VB &SQL

  1. #1

    Thread Starter
    New Member
    Join Date
    May 1999
    Posts
    11

    Post

    I have connected to SQL Server 6.5 through ADO Data Control ( VB 6.0 ) using a DSN.

    I have declared the ADO connection object Dim con As New ADODB.Connection
    & the recordset ( rs ) As New ADODB.Recordset

    When I try to add a new record through VB I get a
    Run-time error '3251'

    "The operation requested by the application is not supported by the provider."

    at - > rs.addnew.

    Please let me know why.
    I would appreciate any help.

    Thanks,
    Vidya.

  2. #2
    Lively Member
    Join Date
    Jan 1999
    Posts
    82

    Post

    Hi,

    Is this all the code or is there more between the declaration and the addnew statement?

    Preeti

  3. #3

    Thread Starter
    New Member
    Join Date
    May 1999
    Posts
    11

    Post

    Hi,

    That's the code.
    I have a command button called Display to display the records.
    Then I have anothere command button Add to add new records thr' VB.

    Thanks,
    Vidya.

  4. #4

    Thread Starter
    New Member
    Join Date
    May 1999
    Posts
    11

    Post

    Hi Jason Williams,

    Thanks a lot for the reply.
    When the VB application is run I want the user to enter data into the table, that is through text boxes in VB.
    I used the DSN.
    Also please send me the function that will connect to SQL Via OLE DB, with error trapping.I would really appreciate your help.
    My email id is ( [email protected] ).

    Thanking you,
    Vidya.



  5. #5
    New Member
    Join Date
    Feb 1999
    Location
    Ft Worth, TX, USA
    Posts
    11

    Post

    I am on ICQ right now, can you log in to it?

    #7292656

  6. #6

    Thread Starter
    New Member
    Join Date
    May 1999
    Posts
    11

    Post


    When I closed the resultset as it is was already open using
    If RS.State = adStateOpen Then RS.
    I get a Run-time error '3704':-
    " The operation requested by the application is not allowed if the object is closed. "

    Thanks,
    Vidya.

  7. #7
    Lively Member
    Join Date
    Jan 1999
    Posts
    82

    Post

    Before you can add a record to a table, you need to connect to the database, and then create an object to that table.

    Are you doing this before you try and add records to the table?

    If yes, what is the code that connects to the database and then opens the table?

    Preeti

  8. #8
    New Member
    Join Date
    Feb 1999
    Location
    Ft Worth, TX, USA
    Posts
    11

    Post

    In order to [addnew] you need to have something you are adding to?

    Dim RS as new ADODB.Recordset
    Dim CN as new ADODB.Connection

    Connect to the database any way you know how... I use the OLE DB, it seems to be the best way.

    SQL$ is a String that holds the SQL query you are going to run.

    SQL$ = "Select * from TABLE"

    'Close the resultset if it is already open
    If RS.State = adStateOpen Then RS.Close

    'Retrieve records from the SQL database
    RS.Open SQL$, CN, adOpenStatic, adLockReadOnly

    Okay, now that you have some records, you can add some data.
    RS.Addnew
    RS("Fieldname1") = "Look"
    RS("Fieldname2") = "At"
    RS("Fieldname3") = "The"
    RS("Fieldname4") = "Data!"
    RS.Update

    And there you go... Simple! If you want, I have a function that will connect to SQL Via OLE DB, with error trapping.

    Jason Williams
    Arlington, TX



    [This message has been edited by JayWms (edited 07-22-1999).]

  9. #9

    Thread Starter
    New Member
    Join Date
    May 1999
    Posts
    11

    Post

    My Connection to the db & then table goes thr' real fine.

    Connect to the database :-

    Private Sub Form_Load()
    Dim con As New ADODB.Connection
    Dim rs
    con.ConnectionString = "DSN=test;uid=sa;pwd=pwd;"
    con.Open
    MsgBox "The Connection is now open!"
    ' Open the recordset rs
    Set rs = New ADODB.Recordset
    rs.CursorType = adOpenKeyset
    rs.LockType = adLockOptimistic
    rs.Open "test", con, , , adCmdTable
    End Sub


    Vidya.

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