[英]How do you pass and recive an output parameter from vb.net to a mysql
Dim Def_Command_MySQL1 As MySql.Data.MySqlClient.MySqlCommand
Def_Command_MySQL1.Parameters.Clear()
Def_Command_MySQL1.CommandText = "SET @OutID = 10;"
or
Def_Command_MySQL1.CommandText = "UPDATE ID_Max1 SET IdMax = IdMax + 1 , @OutID = IdMax + 1 where TypeID>1"
Def_Command_MySQL1.Parameters.Add(New SqlParameter("@OutID", SqlDbType.Int)).Value = 41
Def_Command_MySQL1.Parameters("@OutID").Direction = ParameterDirection.Output
Def_Command_MySQL1.ExecuteNonQuery()
IDMax_Update = Def_Command_MySQL1.Parameters("@OutID").Value
Err.Description "You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '41 = 10' at line 1" String Err.Description "您的 SQL 语法有错误;请查看与您的 MariaDB 服务器版本相对应的手册,了解在第 1 行的 '41 = 10' 附近使用的正确语法" 字符串
or或者
Error = You have an error in your SQL syntax;错误 = 您的 SQL 语法有错误; check the manual that corresponds to your MariaDB server version for the right syntax to use near '1=IdMax + 1 where TypeID>1' at line 1检查与您的 MariaDB 服务器版本相对应的手册,以在第 1 行的 '1=IdMax + 1 where TypeID>1'附近使用正确的语法
First you set AllowUserVariables on True(Default is False in your connection string see https://dev.mysql.com/doc/connector-net/en/connector-net-6-10-connection-options.html首先将 AllowUserVariables 设置为 True(连接字符串中的默认值为 False,请参阅https://dev.mysql.com/doc/connector-net/en/connector-net-6-10-connection-options.https://dev.mysql.com/doc/connector-net/en/connector-net-6-10-connection-options.https
second get rid of the parameter code, because you replace mysql user defined variables @OutID with an actual value , which results in your error message.第二摆脱参数代码,因为您将 mysql 用户定义变量 @OutID 替换为实际值,这会导致您的错误消息。
With和
SET @OutID = 10;"
You set in mysql a user defined variable @OutID to the numer 10.您在 mysql 中将用户定义的变量 @OutID 设置为数字 10。
But in general, following code add two parameters to a insert query但一般来说,以下代码向插入查询添加两个参数
Def_Command_MySQL1.CommandText = "INSERT INTO myTable (myColumn1, myColumn2) VALUES (@C1, @C2)"
Def_Command_MySQL1.Parameters.AddWithValue("@C1", 1)
Def_Command_MySQL1.Parameters.AddWithValue("@C2", 2)
Def_Command_MySQL1.ExecuteNonQuery()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.