Trying to use ODBC .NET data provider, I succeed in
connecting to my DBMS, but am failing to execute a data
reader. Can someone help with syntax? Thanks.
My stored procedure GET_PERSON has four parameters:
status is an output integer, somid is the only input and
is integer, lname is varchar(35) output, fname is varchar
(35) output.
Private Sub Button3_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles Button3.Click
Dim cn As OdbcConnection
Dim cmd As OdbcCommand
Dim parm As OdbcParameter
Dim drdr As OdbcDataReader
cn = New OdbcConnection("Provider=MSDASQL;DSN=net
Practice;ServerDSN=s1032_net;UID=****;PWD=**********;")
cmd = New OdbcCommand("GET_PERSON", cn)
cmd.CommandType = CommandType.StoredProcedure
parm = cmd.Parameters.Add("@somid", OdbcType.Int)
parm.Value = 1
' also tried the line below alone
'cmd = New OdbcCommand("{call GET_PERSON
(null,1,null,null)}", cn)
cn.Open()
MsgBox("Connected") 'this succeeds
drdr = cmd.ExecuteReader() ' "unhandled exception"
MsgBox("Reader executed")
If drdr.Read() Then
txtfn.Text = drdr.GetString(3)
txtln.Text = drdr.GetString(2)
End If
drdr.Close()
cn.Close()
End Sub
Here's the working asp classic code:
Set oCmd = Server.CreateObject("ADODB.COMMAND")
oCmd.activeconnection=oConn
oCmd.CommandText = "GET_PERSON"
oCmd.CommandType = 4
oCmd(0) = NULL
oCmd(1) = 1
oCmd(2) = NULL
oCmd(3) = NULL
oCmd.Execute("GET_PERSON")
%>
<% Response.Write oCmd(3) & " " & oCmd(2) & "<br>" %>
<%
set oCmd.activeconnection = nothing
set oCmd = nothing
set oConn = nothing
%>