简体   繁体   English

您如何将 output 参数从 vb.net 传递和接收到 mysql

[英]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.

相关问题 如何将输出参数从vb.net传递给mysql存储过程? - How do you pass an output parameter from vb.net to a mysql stored procedure? 将 output 参数从 VB.NET 传递并接收到 MySQL - Pass and receive an output parameter from VB.NET to a MySQL 如何通过由查询生成器向导创建的vb.net适配器将参数传递给mysql功能 - how to pass parameter to function of mysql through vb.net adapter which is created by query builder wizard VB.NET 将数据从 mysql 查询传递到 UserControl - VB.NET pass data from mysql query to UserControl 如何从VB.Net启动程序并传递参数? - How do I start a program from VB.Net and pass it arguments? 如何使用查询写入VB.net中的Mysql数据库 - How do I write to a Mysql database in VB.net with a query 如何将数据从MYSQL数据读取器获取到vb.net中的arraylist - How do I get the data from a MYSQL data reader into an arraylist in vb.net 如何在 VB.Net 中使用 UserControl 和 FlowLayoutPanel 从 MySQL 制作自定义表? - How do I make a customized table from MySQL using UserControl and FlowLayoutPanel in VB.Net? 我如何在VB.Net中从另一台计算机连接到mysql数据库? - How do i connect to mysql database from another computer in VB.Net? 如何在mysql,vb.net中将一个表中的不同字段插入另一个表 - How do i insert different fields from one table to another in mysql,vb.net
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM