MySQL的ODBC连接不会增加值 [英] ODBC connection to MySQL won't add values
问题描述
我试图插入从我的asp.net应用价值到我的MySQL数据库。
I'm trying to insert values from my asp.net application into my MySQL database.
在注册页面的人名称
和通
和preSS提交可以填补。
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
不过,这一切确实是添加NULL值到我的数据库。
But all this does is add NULL values into my database.
这是我在做什么错误的任何线索?
Any clues on what I'm doing wrong?
推荐答案
如何切换约定使用?
和参数名称相匹配的列名?
也许是考虑切换到<一个href="http://msdn.microsoft.com/en-us/library/system.data.odbc.odbcparametercollection.addwithvalue.aspx"相对=nofollow> AddWithValue()
如果可以的话。
How about switching convention to use ?
and parameter names matching the column names?
Perhaps consider switching to AddWithValue()
if you can.
从 OdbcParameterCollection.Add
方法
Dim insertSQL As String = "INSERT INTO member(Name, Pass) VALUES (?,?)"
Dim cmd As New OdbcCommand(insertSQL, myconn)
'cmd.Parameters.Add("Name", OdbcType.VarChar).Value = objMember.Name '
cmd.Parameters.AddWithValue("Name", objMember.Name)
cmd.Parameters.AddWithValue("Pass", objMember.Pass)
'Note that with ODBC Command, the ORDER you add to the parameters collection
'matters most. The names of your params don't matter.
我怀疑?
占位符将填充值以作为它们添加到Parameters集合(从的另外一个问题/答案)。
I suspect the ?
placeholders will be filled with the values in order as they're added to the Parameters collection (from another question/answer).
这篇关于MySQL的ODBC连接不会增加值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!