I’m trying to insert values from my asp.net application into my MySQL database.
On the register page people can fill in Name and Pass and press submit.
Public Function InsertMember(ByVal objMember As Member) As Boolean
myconn.Open()
Dim cmd As New OdbcCommand("INSERT INTO member(Name, Pass) VALUES (@Name,@Pass)", myconn)
cmd.CommandType = CommandType.Text
cmd.Parameters.Add("Name", OdbcType.VarChar).Value = objMember.Name
cmd.Parameters.Add("Pass", OdbcType.VarChar).Value = objMember.Pass
cmd.ExecuteNonQuery()
cmd.Dispose()
cmd = Nothing
myconn.Close()
myconn.Dispose()
Return True
End Function
But all this does is add NULL values into my database.
Any clues on what I’m doing wrong?
How about switching convention to use
?and parameter names matching the column names?Perhaps consider switching to
AddWithValue()if you can.From the MSDN
OdbcParameterCollection.AddMethodI suspect the
?placeholders will be filled with the values in order as they’re added to the Parameters collection (from another question/answer).