Results 1 to 8 of 8

Thread: [RESOLVED] [2005] CommandText not Initialized Help Please :)

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2007
    Location
    Iowa
    Posts
    298

    Resolved [RESOLVED] [2005] CommandText not Initialized Help Please :)

    I am changing some code on this program at work and this actually worked before so I guess I broke it.

    I'm getting the error "Execute Reader: CommandText has not been initialized"



    Code:
    Private Function Process_Invoice_HRA(ByVal strCode As String) As Boolean
            Notify("Invoice")
    
            Dim strPlanYear As String
            Dim strEmployerNumber As String
    
            Select Case Mid(strCode, 1, 1)
                Case "("
                    strPlanYear = Mid(strCode, 4, 4)
                    strEmployerNumber = Mid(strCode, 8, strCode.Length - 8)
                Case "-"
                    strPlanYear = Mid(strCode, 4, 4)
                    strEmployerNumber = Mid(strCode, 13, strCode.Length - 13)
            End Select
    
         
            EmployerDataAdapter.SelectCommand.Parameters(0).Value = CInt(strEmployerNumber)
            PlanDataAdapter.SelectCommand.Parameters(0).Value = CInt(strEmployerNumber)
            PlanDataAdapter.SelectCommand.Parameters(1).Value = strPlanYear
    
    
            Try
                DsErEeEp1.Clear()
                EmployerDataAdapter.Fill(DsErEeEp1)
                PlanDataAdapter.Fill(DsErEeEp1)
            Catch ex As Exception
                MsgBox(ex.Message)
            End Try

    EDIT: I'm getting this error on the Fill.

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: [2005] CommandText not Initialized Help Please :)

    I'm a little confused.

    I don't see where you are using a datareader, and I don't see where you are creating the dataadapter before you use it.

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2007
    Location
    Iowa
    Posts
    298

    Re: [2005] CommandText not Initialized Help Please :)

    This is the code that was originally there.


    Code:
    Private Function Process_Invoice_HRA(ByVal strCode As String) As Boolean
            Notify("Invoice")
            Dim strPlanYear As String = Mid(strCode, 4, 4)
            Dim strEmployerNumber As String = Mid(strCode, 8, strCode.Length - 8)
    
            EmployerDataAdapter.SelectCommand.Parameters(0).Value = CInt(strEmployerNumber)
            PlanDataAdapter.SelectCommand.Parameters(0).Value = CInt(strEmployerNumber)
            PlanDataAdapter.SelectCommand.Parameters(1).Value = strPlanYear
    
            DsErEeEp1.Clear()
            EmployerDataAdapter.Fill(DsErEeEp1)
            PlanDataAdapter.Fill(DsErEeEp1)
    
    
            Notify(DsErEeEp1.Tables("Employer").Rows(0).Item("Employer_first_name") & " " & DsErEeEp1.Tables("Employer").Rows(0).Item("Employer_last_name") & " " & strPlanYear)
    And here is the new code.. Why would a Select Statement cause this?


    Code:
      Private Function Process_Invoice_HRA(ByVal strCode As String) As Boolean
            Notify("Invoice")
    
            Dim strPlanYear As String
            Dim strEmployerNumber As String
    
            Select Case Mid(strCode, 1, 1)
                Case "("
                    strPlanYear = Mid(strCode, 4, 4)
                    strEmployerNumber = Mid(strCode, 8, strCode.Length - 8)
                Case "-"
                    strPlanYear = Mid(strCode, 4, 4)
                    strEmployerNumber = Mid(strCode, 13, strCode.Length - 13)
            End Select
    
            EmployerDataAdapter.SelectCommand.Parameters(0).Value = CInt(strEmployerNumber)
            PlanDataAdapter.SelectCommand.Parameters(0).Value = CInt(strEmployerNumber)
            PlanDataAdapter.SelectCommand.Parameters(1).Value = strPlanYear
    
    
                DsErEeEp1.Clear()
                EmployerDataAdapter.Fill(DsErEeEp1)
                PlanDataAdapter.Fill(DsErEeEp1)
         
    
                Notify(DsErEeEp1.Tables("Employer").Rows(0).Item("Employer_first_name") & " " & DsErEeEp1.Tables("Employer").Rows(0).Item("Employer_last_name") & " " & strPlanYear)

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2007
    Location
    Iowa
    Posts
    298

    Re: [2005] CommandText not Initialized Help Please :)

    The Adapter is created graphically.

  5. #5
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: [2005] CommandText not Initialized Help Please :)

    No, your select case would not cause that. All it is doing is parsing an employee number (or, at least, that is what it looks like it is doing)

  6. #6

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2007
    Location
    Iowa
    Posts
    298

    Re: [2005] CommandText not Initialized Help Please :)

    yeah, it's a barcode actually but you're right. But honestly, that's all i changed. And i have the old compiled code and it works. When I step through all of my variables are correct too.

  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2007
    Location
    Iowa
    Posts
    298

    Re: [2005] CommandText not Initialized Help Please :)

    Sorry for wasting your time. I have the weirdest things happen to me all the time with Visual Studio. Probably cause i don't know what i'm doing, or i like to experiment to much. The problem was, I guess, that when I reloaded the existing item (I had messed some stuff up so i reloaded that form in my project to start fresh) It deleted all the command text in the adapters i made graphically. Sorry I wasted your time Hack.

  8. #8
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: [RESOLVED] [2005] CommandText not Initialized Help Please :)

    It was not a waste of my time and I'm glad you got it resolved.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width