anandkasotia
Member
- Joined
- Aug 30, 2010
- Messages
- 6
- Programming Experience
- 1-3
I'm getting an error on aSqlDataReader = aSqlCommand.ExecuteReader(): Must declare the scalar variable "@sqlPolicyNo".
Here's the code:
Here's the code:
VB.NET:
Private Sub RetrievePolicyId(ByRef anAutoPolicy As AutoPolicy)
Try
If aSqlConn.State <> ConnectionState.Open Then
aSqlConn.Open()
End If
aQuery = "Select PolicyId " & _
"From V4Policy " & _
"Where PolicyNo = @sqlPolicyNo " & _
"and SystemCd = @sqlSystemCd " & _
"and StateNo = @sqlStateNo " & _
"and LastActivityDt = @sqlLastActivityDt " & _
"Order By PolicyId"
aSqlParameter = aSqlCommand.Parameters.Add("sqlPolicyNo", SqlDbType.Char, 20)
aSqlParameter.Value = anAutoPolicy.PolicyNumber
aSqlParameter = aSqlCommand.Parameters.Add("sqlSystemCd", SqlDbType.Char, 1)
aSqlParameter.Value = anAutoPolicy.SystemCode
aSqlParameter = aSqlCommand.Parameters.Add("sqlStateNo", SqlDbType.Int)
aSqlParameter.Value = anAutoPolicy.StateNumber
aSqlParameter = aSqlCommand.Parameters.Add("sqlLastActivityDt", SqlDbType.DateTime)
aSqlParameter.Value = anAutoPolicy.LastActivityDate
aSqlCommand = aSqlConn.CreateCommand()
aSqlCommand.CommandText = aQuery
aSqlDataReader = aSqlCommand.ExecuteReader()
If aSqlDataReader.HasRows() Then
While aSqlDataReader.Read
anAutoPolicy.PolicyId = aSqlDataReader.GetInt32(0)
Exit While
End While
Else
anAutoPolicy.Results = "Policy not found in Table" & anAutoPolicy.PolicyNumber
End If
aSqlDataReader.Close()
Catch ex As Exception
MessageBox.Show(ex.Message & " Error in RetrievePolicyId(): " & anAutoPolicy.PolicyNumber, "Fatal Error!!!", MessageBoxButtons.OK, MessageBoxIcon.Error)
Finally
'If aSqlConn.State = ConnectionState.Open Then
' aSqlConn.Close()
'End If
End Try
End Sub