#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2011
    Posts
    17
    Rep Power
    0

    SQL/VB help with code


    Hi, trying to update my phpsql database after this code:

    Try
    For Each itemChecked In Sykkel.clistterreng.CheckedItems
    ListBoxvarer.Items.Add(quote + itemChecked.ToString() + quote)
    conn.Open()
    Dim sqlUpdate As New MySqlCommand("UPDATE Sykkel SET leidut = 1 WHERE CONCAT(sykkel_nr, ' ', sykkel_type) = '" & itemChecked & "'", conn)
    Dim adapter As New MySqlDataAdapter
    Dim tabell As New DataTable

    adapter.SelectCommand = sqlUpdate
    adapter.Fill(tabell)

    conn.Close()
    Dim rad As DataRow
    Dim utleid As String
    For Each rad In tabell.Rows
    utleid = rad("leidut")
    Next rad
    Next
    catch ex As Exception
    MsgBox("Noe gikk feil git")

    End Try

    Can anyone see what's wrong here? If I change the sql sentence to:
    Dim sqlUpdate As New MySqlCommand("UPDATE Sykkel SET leidut = 1", conn)

    It works, but updates the whole table. When I try my sentence in the actual sql website (myphpadmin) that sentence with CONCAT works perfectly :S

    EDIT:
    I see that items.checked makes the string come out like this "a001 terrengsykkel", when i want it to just go: a001 terrengsykkel

    The thing is, if i change the code to:
    Dim sqlUpdate As New MySqlCommand("UPDATE Sykkel SET leidut = 1 WHERE CONCAT(sykkel_nr, ' ', sykkel_type) = itemChecked, conn)
    It should work in theory, atelast the SQL sentence works, but I get an error in VB.
  2. #2
  3. No Profile Picture
    Grumpier old Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jun 2003
    Posts
    14,453
    Rep Power
    4539
    What is a phpsql database? Never heard of it.
    ======
    Doug G
    ======
    Bartender to Rene Descartes "have another beer?" Descartes: "I think not" and he vanished.
    --Alfred Bester
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2011
    Posts
    17
    Rep Power
    0
    Originally Posted by Doug G
    What is a phpsql database? Never heard of it.
    Haha sorry, SQL
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2011
    Posts
    17
    Rep Power
    0
    Basicly, can anyone see the difference between these two?

    SQL:
    UPDATE Sykkel
    SET leidut = 0
    WHERE CONCAT(sykkel_nr, ' ', sykkel_type) = "a001 Terrengsykkel"

    VB:
    Dim sqlUpdate As New MySqlCommand("UPDATE Sykkel SET leidut = 1 WHERE CONCAT(sykkel_nr, ' ', sykkel_type) = " & " " & itemChecked, conn)
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2011
    Posts
    17
    Rep Power
    0
    Originally Posted by oyb1n
    Basicly, can anyone see the difference between these two?

    SQL:
    UPDATE Sykkel
    SET leidut = 0
    WHERE CONCAT(sykkel_nr, ' ', sykkel_type) = "a001 Terrengsykkel"

    VB:
    Dim sqlUpdate As New MySqlCommand("UPDATE Sykkel SET leidut = 1 WHERE CONCAT(sykkel_nr, ' ', sykkel_type) = " & " " & itemChecked, conn)
    EDIT:
    itemChecked values "a001 Terrengsykkel"
  10. #6
  11. No Profile Picture
    Grumpier old Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jun 2003
    Posts
    14,453
    Rep Power
    4539
    SQL is not the name of a database management system either. SQL is the name of the scripting language used by most database systems.

    Use the debugger to see if your sql from vb code is the same as your manual sql.
    ======
    Doug G
    ======
    Bartender to Rene Descartes "have another beer?" Descartes: "I think not" and he vanished.
    --Alfred Bester

IMN logo majestic logo threadwatch logo seochat tools logo