Results 1 to 7 of 7
  1. #1
    Join Date
    Oct 2002
    Posts
    6

    Unanswered: MYVBQL AddNew, Update

    I am using MyVBQL in my project. Well, I have a problem in using AddNew and Update.
    ---- code in my program ---

    Set Tbl = BD_L.Execute(SQL)
    Tbl.AddNew ' problem: EditMode not changed (= MY_EDIT_NONE) if there is no record in the table.
    ......
    Tbl.Update ' subsequently: the record is not updated
    -----------------

    anyone can show me on how to add a new record into a table at very initial state (no record previously).

  2. #2
    Join Date
    Feb 2002
    Posts
    2,232
    What language are you using (visual basic ?) ? What is the SQL string in the execute method ? What is TBL ?

  3. #3
    Join Date
    Oct 2002
    Posts
    6
    I'm using VB. My Idea is using a common method to deal with multiple tables (that's alot of tables with various number of columns) so, I can't use BD_L.Execute("insert into table values (xx,yy,zz)")

    --- here's the info in my code ---
    Global BD_L As MYSQL_CONNECTION
    BD_L.OpenConnection gHostName, gDBUser, passwd, dbname, 3306
    ...
    --------------------------
    Dim Tbl As MYSQL_RS
    Dim SQL As String

    SQL = "SELECT * FROM Table1"
    Set Tbl = BD_L.Execute(SQL)
    Tbl.AddNew ' problem: EditMode not changed (= MY_EDIT_NONE) if there is no record in the table.
    Tbl.Fields(0) = "xx"
    Tbl.Fields(1) = "yy"
    Tbl.Update ' subsequently: the record is not updated
    -----------------

  4. #4
    Join Date
    Feb 2002
    Posts
    2,232
    Which cursortype are you using ? Is this only happening when no record exists in the table - so if at least 1 record exists you have no problem updating/deleting/inserting ? How will you create a common method that requires varying table/field names that you could not accomplish with a dynamic sql statement ?

  5. #5
    Join Date
    Oct 2002
    Posts
    6
    I'm very new to VB. what you mean cursortype?

    yes, if at least 1 record exists I have no problem updating/deleting/inserting

    --- How I create a common method that requires varying table/field names ----

    let say I've table1, table2 ..... table10
    If I don't know what table is being accesing by the user from the vb interface, I only need to have some buttons: delete, addnew, update
    and some combo. So, what I need to do is just

    sql= "select * from " & frm.tag
    Set Tbl = BD.Execute(SQL)
    Tbl.AddNew
    Tbl.Fields(0).Value = .combo(0)
    Tbl.Fields(1).Value = .combo(1)
    .....
    Tbl.Update
    -----------------

  6. #6
    Join Date
    Feb 2002
    Posts
    2,232
    If you can dynamically create the sql statement then you can dynamically create the "insert" statement with the values from the combo boxes - I am a little confused about that. And an insert is much faster than an addnew/update process with a recordset object. Something like sql = "insert into " & frm.tag & " values " & ... (the combo fields) - you may have to be specific on the fields you want to insert if there are more than just the 2. Let me know what process you are trying to encapsulate. I am not opposed to someone doing an addnew/update but in this scenario, insert would be a much better design.

  7. #7
    Join Date
    Oct 2002
    Posts
    6
    Thanks for your reply, since I'm doing a workgroup project so that's a bit difficult for me to change the program structure. Well, it's really help to use INSERT directly in some tricky part.

Posting Permissions

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