ODBC connection in VB.net and Stored Procedures

Joined
Mar 27, 2008
Messages
1
Reaction score
0
Dear all,

I am having problems with the code below. I am trying to access a Stored Procedure in the SQL Server 2005 with VB.net.

Code:
Dim conexaoBD As String

        conexaoBD = "dsn=Base_Servidor_S&S;uid=sa;pwd=sislg#03"
        Dim conn As OdbcConnection = New OdbcConnection(conexaoBD)
        Dim cmd As OdbcCommand = conn.CreateCommand
        cmd.CommandText = "pr_ss_pesquisaDadosUc"
        cmd.CommandType = CommandType.StoredProcedure
        cmd.Parameters.Add(New OdbcParameter("@codigo_uc", OdbcType.Char, 20)).Direction = ParameterDirection.Input
        'cmd.Parameters.Add("", Odbc.OdbcType.Char, _
        '               20).Direction = ParameterDirection.Input
        'cmd.Parameters("@codigo_uc").Value = "000000000106"
        cmd.Parameters(0).Value = "000000000106"
        Try
            conn.Open()
            '  cmd.ExecuteNonQuery()

            Dim dr As OdbcDataReader = cmd.ExecuteReader
            If dr.Read Then
                'Me.leituras_dataHoraAquisicao = BancoDeDados.DBdatetime(dr.Item("DATA_HORA_AQUISICAO"))
            Else
            End If

            dr.Close()

            conn.Close()
            'Return aluno
        Catch ex As SqlException
            Throw New ApplicationException("Erro : " & Microsoft.VisualBasic.Chr(10) & "" + ex.Message)
        End Try
I get the following error when I try to execute the line
ERROR [42000] [Microsoft][ODBC SQL Server Driver][SQL Server]Procedure or Function 'pr_ss_pesquisaDadosUc' expects parameter '@codigo_uc', which was not supplied.

Code:
Dim dr As OdbcDataReader = cmd.ExecuteReader

Anyone could please help me?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top