Cannot cast object type in PgSQLdatareader

Cannot cast object type in PgSQLdatareader

Postby aspirevishal » Wed 14 Nov 2007 13:28

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
aspirevishal
 
Posts: 30
Joined: Fri 31 Aug 2007 03:30
Location: India

Postby Alexey » Thu 15 Nov 2007 12:08

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.
Alexey
 
Posts: 2756
Joined: Mon 13 Mar 2006 07:43

Postby aspirevishal » Fri 16 Nov 2007 07:01

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
aspirevishal
 
Posts: 30
Joined: Fri 31 Aug 2007 03:30
Location: India

Postby aspirevishal » Fri 16 Nov 2007 11:17

aspirevishal
 
Posts: 30
Joined: Fri 31 Aug 2007 03:30
Location: India

Postby Alexey » Fri 16 Nov 2007 12:23

Well done. But why do you use asynchronous method?
Alexey
 
Posts: 2756
Joined: Mon 13 Mar 2006 07:43


Return to dotConnect for PostgreSQL