MySQL的ODBC连接不会增加值 [英] ODBC connection to MySQL won't add values

查看:154
本文介绍了MySQL的ODBC连接不会增加值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图插入从我的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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆