Results 1 to 7 of 7

Thread: SQL Database Problem

  1. #1

    Thread Starter
    Hyperactive Member richy's Avatar
    Join Date
    Jan 1999
    Location
    Liverpool, England
    Posts
    353

    Angry

    Connected to a database using the following code:

    Set dbase = Workspaces(0).OpenDatabase(globaldir + "diary")

    This connects fine. I can then select some values from this database and one of the tables by doing the following:

    sqlstring = "SELECT * FROM tbldescrip"
    Set rs = dbase.OpenRecordset(sqlstring, dbOpenDynaset)

    and this works fine. The problem occurs when I try to use the insert into sql function.
    I'm currently doing the following:

    sqlstring = "INSERT INTO tbldescrip VALUES ('1st value', '2nd value', '3rd value', '4th value')"
    Set rs = dbase.OpenRecordset(sqlstring, dbOpenDynaset)

    and I'm told that it's an invalid operation. I've tested all my rights, and columns in my database, and they are fine.


    Please help.

  2. #2
    Addicted Member
    Join Date
    Sep 1999
    Location
    Philippines
    Posts
    196
    Instead of using Recordset, use command

  3. #3

    Thread Starter
    Hyperactive Member richy's Avatar
    Join Date
    Jan 1999
    Location
    Liverpool, England
    Posts
    353
    there is no command from what i can see in the vb auto complete drop down list.

  4. #4
    Member
    Join Date
    Aug 2000
    Posts
    60
    Rives,
    richy is using DAO there is no command object there.

    richy,

    I've never tried using it like that. Why don't you try the following after opening the recordset with either a SELECT statement of just the table name:

    Recordset.AddNew
    Recordset.Fields("Field1") = Value1
    Recordset.Fields("Field2") = Value2 etc....

    Recordset.Update

    Hope this helps.
    Barend
    JHB-SA

    Nothing is impossible, except skiing through a revolving door.

  5. #5

    Thread Starter
    Hyperactive Member richy's Avatar
    Join Date
    Jan 1999
    Location
    Liverpool, England
    Posts
    353
    the reason is that we are making it faster and running it completely through code rather than using the actual control. To do the code that you see above, you don't even use the data control.

  6. #6
    Junior Member
    Join Date
    Oct 2000
    Location
    High Wycombe, UK
    Posts
    25

    re SQL Database Problem

    Try using the execute method like so

    dbase.execute sqlstring
    Ciao.........Gary

    VB6, SQL Server 7, Access 97

  7. #7

    Thread Starter
    Hyperactive Member richy's Avatar
    Join Date
    Jan 1999
    Location
    Liverpool, England
    Posts
    353
    Cheers for everyones help.
    I suddenly realised when reading Gary Juleffs post that you can't set a recordset to an insert statement, so in other words the line went from:

    Set rs = dbase.OpenRecordset(sqlstring, dbOpenDynaset)

    to

    dbase.OpenRecordset(sqlstring, dbOpenDynaset)

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