G
Guest
I have code that works fine if there is a date to feed the parameter...
if there isn't...
It seems as though I've trapped the parameter from even presenting itself
with:
If Len(sGROUP) <> 0 And Len(sSGR) <> 0 And FROMdt <> "" Then...
'AND just to be redundant...
If FROMdt <> "" Then
.Add("@FROM", SqlDbType.DateTime).Value = FROMdt
Else
.Add("@FROM", SqlDbType.DateTime).Value = DBNull.Value
End If
But I keep getting the following error
The string was not recognized as a valid DateTime. There is a unknown word
starting at index 1.
(what am I missing?)
'See the majority of this function below:
Public Shared Function GetMember(ByVal lMRN As Integer, _
ByVal sGROUP As String, _
ByVal sSGR As String, _
ByVal FROMdt As String) As Member
Dim Member As New Member
Dim drMember As SqlDataReader
Dim conMembers As SqlConnection = GetMembershipConnection()
'has all possible parameters
If Len(sGROUP) <> 0 And Len(sSGR) <> 0 And FROMdt <> "" Then
Dim sSqlCommand = "SELECT MRN, MemNAME, SSN, DOB, SEX, HML, PHN,
[GROUP], SGR, REL, PROVIDER, PCL, [EXP], [FROM-DT], [THRU-DT] FROM MEMBERSHIP
WHERE (MRN = @MRN) AND ([GROUP]=@GROUP) AND (SGR = @SGR) AND ([FROM-DT] =
@FROM)"
Dim cmdMember As New SqlCommand(sSqlCommand, conMembers)
With cmdMember.Parameters
.Add("@MRN", SqlDbType.Int).Value = lMRN
.Add("@GROUP", SqlDbType.NVarChar).Value = sGROUP
.Add("@SGR", SqlDbType.NVarChar).Value = sSGR
If FROMdt <> "" Then
.Add("@FROM", SqlDbType.DateTime).Value = FROMdt
Else
.Add("@FROM", SqlDbType.DateTime).Value = DBNull.Value
End If
End With
conMembers.Open()
drMember = cmdMember.ExecuteReader(CommandBehavior.SingleRow)
if there isn't...
It seems as though I've trapped the parameter from even presenting itself
with:
If Len(sGROUP) <> 0 And Len(sSGR) <> 0 And FROMdt <> "" Then...
'AND just to be redundant...
If FROMdt <> "" Then
.Add("@FROM", SqlDbType.DateTime).Value = FROMdt
Else
.Add("@FROM", SqlDbType.DateTime).Value = DBNull.Value
End If
But I keep getting the following error
The string was not recognized as a valid DateTime. There is a unknown word
starting at index 1.
(what am I missing?)
'See the majority of this function below:
Public Shared Function GetMember(ByVal lMRN As Integer, _
ByVal sGROUP As String, _
ByVal sSGR As String, _
ByVal FROMdt As String) As Member
Dim Member As New Member
Dim drMember As SqlDataReader
Dim conMembers As SqlConnection = GetMembershipConnection()
'has all possible parameters
If Len(sGROUP) <> 0 And Len(sSGR) <> 0 And FROMdt <> "" Then
Dim sSqlCommand = "SELECT MRN, MemNAME, SSN, DOB, SEX, HML, PHN,
[GROUP], SGR, REL, PROVIDER, PCL, [EXP], [FROM-DT], [THRU-DT] FROM MEMBERSHIP
WHERE (MRN = @MRN) AND ([GROUP]=@GROUP) AND (SGR = @SGR) AND ([FROM-DT] =
@FROM)"
Dim cmdMember As New SqlCommand(sSqlCommand, conMembers)
With cmdMember.Parameters
.Add("@MRN", SqlDbType.Int).Value = lMRN
.Add("@GROUP", SqlDbType.NVarChar).Value = sGROUP
.Add("@SGR", SqlDbType.NVarChar).Value = sSGR
If FROMdt <> "" Then
.Add("@FROM", SqlDbType.DateTime).Value = FROMdt
Else
.Add("@FROM", SqlDbType.DateTime).Value = DBNull.Value
End If
End With
conMembers.Open()
drMember = cmdMember.ExecuteReader(CommandBehavior.SingleRow)