locked
hi there am new to that RRS feed

  • Question

  • User-7838209 posted

    i wana retrive data from oracle database, depending on the value user enter

    but i always get an error 
    "operation not valid due to current stat of object"

    i think the error comes from if "  If dr.HasRows Then "

    here is the code please  help

    Protected Sub TextBox1_TextChanged(ByVal sender As Object, ByVal e As EventArgs)
    Dim dt As DataTable = DirectCast(ViewState("CurrentTable"), DataTable)
    Dim rowIndex As Integer = 0
    Dim strEMPBRTDAT As String
    Dim strEMPPRJCDE As String
    Dim strEMPBRN As String
    If dt.Rows.Count > 0 Then
    For i As Integer = 0 To dt.Rows.Count - 1
    Dim box1 As TextBox = DirectCast(Gridview1.Rows(rowIndex).Cells(1).FindControl("TextBox1"), TextBox)
    Dim box2 As TextBox = DirectCast(Gridview1.Rows(rowIndex).Cells(2).FindControl("TextBox2"), TextBox)
    Try
    If box1.Text.Length <> 0 Then
    dr = conn.MyReader("SELECT EMPNAM, EMPBRTDAT, EMPPRJCDE, EMPBRN, EMPNBR FROM EMPBAS WHERE(EMPNBR =':box1.Text' )")
    Response.Write("box1:" + box1.Text + "")
    If dr.HasRows Then
    While dr.Read()

    box2.Text = dr(0).ToString
    strEMPBRTDAT = dr(1).ToString
    'strEMPPRJCDE = dr(2).ToString
    ' strEMPBRN = dr(3).ToString
    ' Console.WriteLine(dr("strEMPBRTDAT"))
    ' Console.WriteLine(dr("strEMPPRJCDE"))
    ' conn.MyInsertclnc("insert into CLNCVST (EMPNAM , EMPNBR , EMPBRTDAT , EMPPRJCDE , EMPBRN ) values('" + box1.Text + "','" + box2.Text + "', '" + strEMPBRTDAT + "','" + strEMPPRJCDE + "' , '" + strEMPBRN + "' )")

    End While

    End If
    Response.Redirect("www.gogo.com")
    End If
    Catch ex As Exception
    Response.Write("<script>alert('the select : " + ex.Message.ToString + "') </script>")
    Finally
    'dr.Close()
    End Try

    rowIndex += 1
    Next
    End If
    End Sub

    Monday, April 22, 2013 5:56 AM

All replies

  • User1241621633 posted

    If dr.HasRows Then
    While dr.Read()

    box2.Text = dr(0).ToString
    strEMPBRTDAT = dr(1).ToString
    'strEMPPRJCDE = dr(2).ToString
    ' strEMPBRN = dr(3).ToString
    ' Console.WriteLine(dr("strEMPBRTDAT"))
    ' Console.WriteLine(dr("strEMPPRJCDE"))
    ' conn.MyInsertclnc("insert into CLNCVST (EMPNAM , EMPNBR , EMPBRTDAT , EMPPRJCDE , EMPBRN ) values('" + box1.Text + "','" + box2.Text + "', '" + strEMPBRTDAT + "','" + strEMPPRJCDE + "' , '" + strEMPBRN + "' )")

    End While

    End If

    You can retrieve data by removing "IF dr.HasRows" Only While loop will working fine

    Monday, April 22, 2013 6:00 AM
  • User-7838209 posted

    i tried same error

    i also checked the sql code its working fine

    Monday, April 22, 2013 6:06 AM
  • User1241621633 posted

    shery_l


    If dr.HasRows Then
    While dr.Read()

    box2.Text = dr(0).ToString
    strEMPBRTDAT = dr(1).ToString
    'strEMPPRJCDE = dr(2).ToString
    ' strEMPBRN = dr(3).ToString
    ' Console.WriteLine(dr("strEMPBRTDAT"))
    ' Console.WriteLine(dr("strEMPPRJCDE"))
    ' conn.MyInsertclnc("insert into CLNCVST (EMPNAM , EMPNBR , EMPBRTDAT , EMPPRJCDE , EMPBRN ) values('" + box1.Text + "','" + box2.Text + "', '" + strEMPBRTDAT + "','" + strEMPPRJCDE + "' , '" + strEMPBRN + "' )")

    End While

    Try to call the insert query outside the while loop 

    or first close the reader and close the connection 

    and then open the connection and call the insert query

    Monday, April 22, 2013 6:15 AM
  • User-7838209 posted

    shery_l


    If dr.HasRows Then
    While dr.Read()

    box2.Text = dr(0).ToString
    strEMPBRTDAT = dr(1).ToString

    End While

    end if


    the error still presist

    Monday, April 22, 2013 6:27 AM