none
Datareader.HasRows???

    Question

  • I have a windows form that i want to insert data if no row exsist and updata data if the row exsist, so far i have

    If dr.HasRow =  True Then

    Update

    Else

    Insert

    Is this the right way to go about it....if so why do i get an Object not set to the instance of an object exception.....any help would be great thanks.......

    Monday, March 27, 2006 6:47 PM

Answers

  • Hello.

    I think what you are trying to do is:

    if dr.hasrows then

      while dr.read

        do some stuff

      end while

    else

      do something else

    end if

     

    However, you cannot update a database from a datareader. It is firehose of data that is only one way. You would probably have to have a procedure that updates the database and pass in the data from the datareader that you want updated.

    I hope this helps.

     

    Tuesday, March 28, 2006 9:15 PM

All replies

  • Hello.

    I think what you are trying to do is:

    if dr.hasrows then

      while dr.read

        do some stuff

      end while

    else

      do something else

    end if

     

    However, you cannot update a database from a datareader. It is firehose of data that is only one way. You would probably have to have a procedure that updates the database and pass in the data from the datareader that you want updated.

    I hope this helps.

     

    Tuesday, March 28, 2006 9:15 PM
  • Thanks thats what i was trying to do but i would get an exception that my object was not set to an instance of an object....That makes sense thanks...
    Wednesday, March 29, 2006 2:18 AM
  • can you explain me sir :

    cmd = New OleDb.OleDbCommand(sqlstr, con)
            dr = cmd.ExecuteReader()
            Dim vale As Integer
            If dr.HasRows Then


                While dr.Read

                    vale = dr(0)

                End While
            End If

      I have the problem in "dr=cmd.executereader"

    and the first condition "if dr.hasrows"

    and the next condition "while dr.read

    vale = dr(0)      "

    thanks for telling  me ! :)

                 
    Friday, June 06, 2014 8:38 PM