代码如下 :
Dim constr As String
constr = "SERVER=127.0.0.1;user id=root;password=1;database=call_id "
Dim cn As MySql.Data.MySqlClient.MySqlConnection = New MySql.Data.MySqlClient.MySqlConnection
cn.ConnectionString = constr
Dim cmd As MySql.Data.MySqlClient.MySqlCommand
cn.Open()
cmd = cn.CreateCommand
cmd.Connection = cn
cmd.CommandText = "insert linker(Telephone) values(@Telephone) "
cmd.Parameters.Add( "@Telephone ", MySql.Data.MySqlClient.MySqlDbType.VarChar).Value = "8889 "
cmd.ExecuteNonQuery()
cn.Close()
代码上面代码 插入的 Telephone 字段是空的
如果不使用 参数 ,使用 cmd.CommandText = "insert linker(Telephone) values( '8899 ') " , 这样就正常
请问为什么 使用 参数不能插入???
------解决方案--------------------------------------------------------
dim x
cmd.CommandText = "insert linker(Telephone) values(@Telephone) "
x=cmd.Parameters.Add( "@Telephone ", MySql.Data.MySqlClient.MySqlDbType.VarChar)
x.Value = "8889 "
cmd.ExecuteNonQuery()
这样试试
------解决方案--------------------------------------------------------
cmd.CommandText = "insert linker(Telephone) values(@Telephone) "
MySQL中的不是用@而是和?
换成
cmd.CommandText = "insert linker(Telephone) values(?Telephone) "
cmd.Parameters.Add( "?Telephone ", MySql.Data.MySqlClient.MySqlDbType.VarChar).Value = "8889 "