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“您的SQL语法有错误;检查与MariaDB服务器版本对应的手册,以获得在第1行'41 = 10‘附近使用的正确语法。
或
错误=您的SQL语法有错误;请检查与MariaDB服务器版本对应的手册,以获得在'1=IdMax +1(其中TypeID>1在第1行
上)附近使用的正确语法。
发布于 2020-04-03 13:48:49
首先,将AllowUserVariables设置为True(连接字符串中默认为False,请参见https://dev.mysql.com/doc/connector-net/en/connector-net-6-10-connection-options.html )
其次,去掉参数代码,因为您将mysql用户定义的变量@OutID替换为实际值,这将导致您的错误消息。
使用
SET @OutID = 10;"在mysql中将用户定义的变量@OutID设置为numer 10。
但是通常情况下,下面的代码向insert查询添加两个参数
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()https://stackoverflow.com/questions/61012987
复制相似问题