ODBC connection in VB.net and Stored Procedures

Discussion in '.NET' started by guizonatto, Mar 27, 2008.

  1. guizonatto

    guizonatto

    Joined:
    Mar 27, 2008
    Messages:
    1
    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
    Code:
    Dim dr As OdbcDataReader = cmd.ExecuteReader
    
    Anyone could please help me?
     
    guizonatto, Mar 27, 2008
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Taras
    Replies:
    2
    Views:
    4,823
    Rick Spiewak
    Oct 5, 2003
  2. Max
    Replies:
    5
    Views:
    388
  3. Elliot M. Rodriguez, MCSD

    Re: crystal reports and asp.net stored procedures

    Elliot M. Rodriguez, MCSD, May 21, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    481
    Elliot M. Rodriguez, MCSD
    May 21, 2004
  4. Ricardo Magalhaes
    Replies:
    4
    Views:
    13,572
    Ricardo Magalhaes
    Jun 21, 2005
  5. Chris Hall
    Replies:
    0
    Views:
    129
    Chris Hall
    Nov 15, 2006
Loading...

Share This Page