[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.
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.
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)
Re: [2005] CommandText not Initialized Help Please :)
The Adapter is created graphically.
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)
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.
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.
Re: [RESOLVED] [2005] CommandText not Initialized Help Please :)
It was not a waste of my time and I'm glad you got it resolved. :)