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.
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))
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()
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.
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.
If cmd.ExecuteNonQuery() > 0 Then
XML_PaisOrigen = command.Parameters(1).Value.ToString
Else
MsgBox("Nothing!")
End If
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.