how to get data from a stored procedure??

trend

Well-known member
Joined
Oct 12, 2004
Messages
171
I am suppose to run a stored procedure.. and I will get a null or true output from the SP.

but I am lost on how to do this..

here is my code:

Code:
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim MyConnection As New OleDbConnection("Provider=SQLOLEDB.1;User Id=" & TextBox1.Text & ";Password=" & TextBox2.Text & ";Initial Catalog=WeGIR Member Data;Data Source=secure.server.com;Use Encryption for Data=True")
        Dim ds As DataSet
        Dim da As OleDbDataAdapter
        Dim myCmd As New OleDb.OleDbCommand("sp_ValidateLogin")
        Dim myReader As OleDb.OleDbDataReader

        myCmd.Connection = MyConnection
        myCmd.CommandType = CommandType.StoredProcedure

        Try
            MyConnection.Open()
            TextBox3.Text = "database open"

            Dim ValidateLogin As String = "EXECUTE sp_ValidateLogin"
            Dim Results As New OleDbDataAdapter(ValidateLogin, MyConnection)
            ds = New DataSet
            da.Fill(ds, "Results")

            myReader = myCmd.ExecuteReader()

            Do While myReader.Read
                TextBox4.Text = myReader.Read
            Loop

            myReader.Close()



            MyConnection.Close()

            TextBox3.Text = TextBox3.Text & vbNewLine & "database closed"

        Catch myerror As MySqlException
            TextBox3.Text = "error"

        Finally
            If MyConnection.State <> ConnectionState.Closed Then MyConnection.Close()
        End Try

    End Sub


How am I suppose to compare the output to either true or null?


thanks
Lee
 
First of all you dont need a reader.

Code:
Dim myCmd As New OleDb.OleDbCommand("sp_ValidateLogin", MyConnection)
myCmd.CommandType = CommandType.StoredProcedure

if( myCmd.ExecuteScalar() == DBNull.Value)

This should do the trick, depending of the implementation of "sp_ValidateLogin"
 
Back
Top