Results 1 to 6 of 6

Thread: Help: joining 2 statement (Insert and Update)

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    May 2013
    Posts
    328

    Help: joining 2 statement (Insert and Update)

    Is it possible to join 2 different statement in one query?

    Code:
    I use this to insert record
    Dim strQry As String
    
        strQry = "INSERT INTO tab2 " & _
             "(LinkID, Addr, Remarks) " & _
             "VALUES (" & _
             "'" & txtLink.Text & "', " & _
             "'" & txtAddr.Text & "', " & _
             "'" & txtRemarks.Text & "'" & _
             ")"
            
        conn.Execute strQry
    
    I use this to update
    Dim strQry As String
    
        strQry = "UPDATE tab1 SET " & _
             "Addr='" & txtAddr.Text & "', Remarks='" & txtRemarks.Text & "' " & _
             "WHERE LinkID='" & txtLink.Text & "'"
            
        conn.Execute strQry

    How can I combine both of these?


    any help?

  2. #2

    Thread Starter
    Hyperactive Member
    Join Date
    May 2013
    Posts
    328

    Re: Help: joining 2 statement (Insert and Update)

    Additional information:

    For example:

    I insert record on table2 named 'tab2'
    LinkID = 'E-001'
    Address = txtaddr.Text
    Remarks = txtRemarks.Text

    At the same time it must update table1 name 'tab1'
    based on new inserted record using (LinkID field).

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    May 2013
    Posts
    328

    Re: Help: joining 2 statement (Insert and Update)

    In mysql, query worked well.

    Code:
    UPDATE `tab1` SET `Addr`='SPL',`Remarks`='NEW HOME' WHERE `LinkID`='E-001';INSERT INTO `tab2` (`LinkID`,`Addr`,`Remarks`) VALUES ('E-001','SPL', 'NEW HOME');
    But when I tried to run it in vb6, error occurs.

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    May 2013
    Posts
    328

    Re: Help: joining 2 statement (Insert and Update)

    Name:  Untitled.png
Views: 91
Size:  8.1 KB

  5. #5
    PowerPoster make me rain's Avatar
    Join Date
    Sep 2008
    Location
    india/Hubli
    Posts
    2,208

    Re: Help: joining 2 statement (Insert and Update)

    meaning is that if you insert some value in some table ( say in this case tab1)
    basing on the the inserted values another table ( say tab2) will get updated / inserted etc..
    so that tab2 is a watch dog or what ever

    by the error details it appears that you are using MySQL
    use the TRIGGERS of MySQL it does lot work for you , just google it.
    next important is you are using ODBC 3.51 driver , nope don't use it mysql is providing dot net connector just download and use it

    and as for as the error is concern it points to the error in the SQL syntax
    i would like to draw your attention to this link , which is similar to your issue
    The averted nuclear war
    My notes:

    PrOtect your PC. MSDN Functions .OOP LINUX forum
    .LINQ LINQ videous
    If some one helps you please rate them with out fail , forum doesn't expects any thing other than this

  6. #6
    PowerPoster make me rain's Avatar
    Join Date
    Sep 2008
    Location
    india/Hubli
    Posts
    2,208

    Re: Help: joining 2 statement (Insert and Update)

    One more important thing is
    it is possible to execute INSERT and UPDATE statements with single command object
    for safe side use MySql TRANSACTION
    The averted nuclear war
    My notes:

    PrOtect your PC. MSDN Functions .OOP LINUX forum
    .LINQ LINQ videous
    If some one helps you please rate them with out fail , forum doesn't expects any thing other than this

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