Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27196

Parametized Queries Using MySQL doesn't work...

$
0
0
Can someone please tell me what I'm doing wrong here...when I use the Parameterized queries, the Update does not work....if I hard type the info...it works...if I add info by way of setting the textbox and labels...it works...but I REALLY want to use parameters...any help? All field are VarChar, except "Score" which is an integer......

Code:

Try
            Dim cmd As New MySqlCommand
            cmd.Connection = CN
            If CN.State = ConnectionState.Closed Then
                CN.Open()
            End If
         
            cmd.CommandText = "UPDATE studentclasses SET ClassCompleted=?Answer, Score=?Score, Result=?Result WHERE classID=?classID AND studentID=?studentID"
            cmd.Parameters.AddWithValue("?Answer", cbxClassStatus.Text)
            cmd.Parameters.AddWithValue("?Score", txtExamScore.Text.ToString)
            cmd.Parameters.AddWithValue("?Result", lblStudentResult.Text.ToString)
            cmd.Parameters.AddWithValue("?classID", lblClassName.Text.ToString)
            cmd.Parameters.AddWithValue("?studentID", lblStudentID.Text.ToString)
            MsgBox(cmd.CommandText)
            cmd.ExecuteNonQuery()

            MsgBox("Update Complete.")


        Catch ex As Exception
            MsgBox(ex.Message)

        Finally
            CN.Close()
        End Try


Viewing all articles
Browse latest Browse all 27196

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>