It's because your 1st query is returning a field called
CountPerPount
and your 2nd query is returning a field called
CPP
You then have a section of code ...
If PostBlendGradingTblDataReader("CountPerPound").ToString <> "" And ShiftSnapShot = 1 Then
Me.txtCPP.Text = CType(PostBlendGradingTblDataReader("CountPerPound").ToString, Double)
ElseIf PostBlendGradingTblDataReader("CPP").ToString <> "" And ShiftSnapShot = 2 Then
Me.txtCPP.Text = CType(PostBlendGradingTblDataReader("CPP").ToString, Double)
But if ShiftSnapShot = 2 then there is no column called
CountPerPount
returned - and the code will throw an error.
I'm not sure how VB.NET evaluates an
if
statement - if it fails when the first condition fails and does not attempt to evaluate the next condition, then simply check the value of ShiftSnapShot first and then the returned column ...e.g.
If ShiftSnapShot = 1 And PostBlendGradingTblDataReader"CountPerPound").ToString <> ""
Alternatively use the same column name in your sql i.e.
select avg(CountPerPound) as CountPerPound