存储过程 VB.NET MYSQL

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/25375919/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-17 18:03:35  来源:igfitidea点击:

Stored Procedures VB.NET MYSQL

mysqlsqlvb.netstored-proceduresdbnull

提问by Bryan

Hello I still having problems, it brings me DBnull and I tried the Store procedure and works. This is my code. If someone could help me I will appreciate.

您好,我仍然遇到问题,它给我带来了 DBnull,我尝试了 Store 过程并且可以正常工作。这是我的代码。如果有人可以帮助我,我将不胜感激。

        conexion.Open()
        command.Connection = conexion
        command.CommandText = "TraerPaisOrigen"
        command.CommandType = CommandType.StoredProcedure

        command.Parameters.AddWithValue("@Cod_Dua", TxtCodDUA.Text)
        command.Parameters("@Cod_Dua").Direction = ParameterDirection.Input



        command.Parameters.AddWithValue("@_PaisOrigen", MySqlDbType.VarChar)
        command.Parameters("@_PaisOrigen").Direction = ParameterDirection.Output
        command.ExecuteNonQuery()

        'XML_PaisOrigen is a String

        XML_PaisOrigen = command.Parameters(0).Value.ToString




        conexion.Close()

My Store Procedured

我的商店程序

CREATE PROCEDURE TraerPaisOrigen( IN Cod_Dua INT, OUT _PaisOrigen VARCHAR(2))

采纳答案by jmcilhinney

This:

这个:

command.Parameters.AddWithValue("@Cod_Dua", TxtCodDUA.Text)
command.Parameters("@Cod_Dua").Direction = ParameterDirection.Input

should be this:

应该是这样的:

command.Parameters.AddWithValue("@Cod_Dua", CInt(TxtCodDUA.Text))

This:

这个:

command.Parameters.AddWithValue("@_PaisOrigen", MySqlDbType.VarChar)
command.Parameters("@_PaisOrigen").Direction = ParameterDirection.Output

should be this:

应该是这样的:

command.Parameters.Add("@_PaisOrigen", MySqlDbType.VarChar, 2).Direction = ParameterDirection.Output

This:

这个:

XML_PaisOrigen = command.Parameters(0).Value.ToString

should be this:

应该是这样的:

XML_PaisOrigen = command.Parameters(1).Value.ToString()

回答by Bryan

         Try
            conexion.Open()
            command.Connection = conexion
            command.CommandText = "TraerPaisOrigen"
            command.CommandType = CommandType.StoredProcedure

            command.Parameters.AddWithValue("@Cod_Dua", CInt(TxtCodDUA.Text))
            command.Parameters("@Cod_Dua").Direction = ParameterDirection.Input              
            command.Parameters.Add("@_PaisOrigen", MySqlDbType.VarChar, 2).Direction = ParameterDirection.Output
            command.ExecuteNonQuery()

            XML_PaisOrigen = command.Parameters(1).Value.ToString

           conexion.Close()

        Catch ex As Exception
            MsgBox(ex.Message & vbCrLf & "Error al ejecutar << " & ex.Message, MsgBoxStyle.Critical, "Test")

        End Try

This how I call the SP in DB in Mysql and works perfect.

这就是我如何在 Mysql 中调用 DB 中的 SP 并且完美运行。

SET @Cod_Dua=1;
CALL TraerPaisOrigen(@Cod_Dua,@_PaisOrigen);
SELECT @_PaisOrigen;

I am really losing my mind, I have look tutorials and video tutorials and all they do the same or similar. What else could be that SP is not sending me an answer from DB? I have test this and doesn't bring nothing. Always goes to the else.

我真的疯了,我看过教程和视频教程,它们都做相同或相似的事情。SP 没有从 DB 向我发送答复还有什么可能?我对此进行了测试,并没有带来任何东西。总是去别的。

    If cmd.ExecuteNonQuery() > 0 Then
            XML_PaisOrigen = command.Parameters(1).Value.ToString
        Else
            MsgBox("Nothing!")
        End If