Page 1 of 1

Cannot cast object type in PgSQLdatareader

Posted: Wed 14 Nov 2007 13:28
by aspirevishal

Code: Select all

       Try
            PgSqlConnection1.Open()
            command = PgSqlConnection1.CreateCommand()
            Dim uparam, pparam As New CoreLab.PostgreSql.PgSqlParameter
            command.Parameters.Add("uparam", TextBox1.Text)
            command.Parameters.Add("pparam", TextBox2.Text)
            command.CommandText = "select * from authuser where uname = :uparam AND passwd = :pparam"
            command.Prepare()
            Dim readata As CoreLab.PostgreSql.PgSqlDataReader = command.BeginExecuteReader()
            While readata.Read()
                Dim rowdata As CoreLab.PostgreSql.PgSqlRow = readata.GetPgSqlRow(0)
                If rowdata Is Nothing Then
                    Label3.Text = "Retry Incorrect login or password "
                    PgSqlConnection1.Close()
                Else
                    Me.Hide()
                    base.Show()
                End If
            End While
        Catch ex As Exception
            MsgBox("An Error occured please contact administrator" & Chr(13) & ex.Message)
        End Try
On executing it throws a exception

unable to cast object of type 'system.runtime.remoting.messageing.asyncresult' to type
'corelab.postgreSQL.pgsqldatareader'


This code simply checks the username and password in the database if a result row is returned login else exit

Posted: Thu 15 Nov 2007 12:08
by Alexey
This is a designed behaviour, because BeginExecuteReader() method returns object of type IAsyncResult, but not of type PgSqlDataReader.
For more information please read PostgreSQLDirect .NET documentation.

Posted: Fri 16 Nov 2007 07:01
by aspirevishal
Can you please guide me how to accomplish the task. Like get value from the text box and match their value with a SQL select query .

If the SQL query returns a row it is a success else fail

Posted: Fri 16 Nov 2007 11:17
by aspirevishal
I found the answer . Interested people may reach

http://aspireproject.blogspot.com/2007/ ... login.html

Posted: Fri 16 Nov 2007 12:23
by Alexey
Well done. But why do you use asynchronous method?