G
Guest
I know the connection works, but maybe it's the fact that I am referrring to
a View for this DataAdapter?
Does anyone know what would cause the following code to generate a:
"Specified Cast is not valid"?
Dim sMemberCon As String = ConfigurationSettings.AppSettings("SQLConn")
cnSQL.ConnectionString = sMemberCon
cnSQL.Open()
'daMembers_SQL.SelectCommand.CommandType =
CommandType.StoredProcedure
Dim cmdFillMemberSelect As New
SqlCommand("qMemberSelect", cnSQL)
cmdFillMemberSelect.CommandType =
CommandType.StoredProcedure
Dim pMRN As New SqlParameter("@MRN", SqlDbType.Int)
Dim pMemName As New SqlParameter("@MemNAME",
SqlDbType.NVarChar, 40)
Dim pDOB As New SqlParameter("@DOB", SqlDbType.DateTime)
Dim pSSN As New SqlParameter("@SSN", SqlDbType.NVarChar,
9)
Dim pSEX As New SqlParameter("@SEX", SqlDbType.NVarChar,
1)
'Add the parameters only if the textbox value was filled
in
If Session("ssMRN") <> 0 Then
pMRN = Session("ssMRN")
cmdFillMemberSelect.Parameters.Add(pMRN)
End If
If Len(Session("ssNAME")) <> 0 Then
pMemName = Session("ssNAME")
cmdFillMemberSelect.Parameters.Add(pMemName)
End If
If Len(Session("ssDOB")) <> 0 Then
pDOB = Session("ssDOB")
cmdFillMemberSelect.Parameters.Add(pDOB)
End If
If Len(Session("ssSSN")) <> 0 Then
pSSN = Session("ssSSN")
cmdFillMemberSelect.Parameters.Add(pSSN)
End If
If Len(Session("ssSEX")) <> 0 Then
pSEX = Session("ssSEX")
cmdFillMemberSelect.Parameters.Add(pSEX)
End If
'Fill the datatable with the filtered selection
'daMembers_SQL.Fill(dsMembers, "qMemberSelect")
cmdFillMemberSelect.ExecuteNonQuery()
daMemberResults.Fill(DsMemberResults1, "vMemberResults")
DGMembers.DataMember = "vMemberResults"
DGMembers.DataSource =
DsMemberResults1.Tables("vMemberResults").DefaultView
a View for this DataAdapter?
Does anyone know what would cause the following code to generate a:
"Specified Cast is not valid"?
Dim sMemberCon As String = ConfigurationSettings.AppSettings("SQLConn")
cnSQL.ConnectionString = sMemberCon
cnSQL.Open()
'daMembers_SQL.SelectCommand.CommandType =
CommandType.StoredProcedure
Dim cmdFillMemberSelect As New
SqlCommand("qMemberSelect", cnSQL)
cmdFillMemberSelect.CommandType =
CommandType.StoredProcedure
Dim pMRN As New SqlParameter("@MRN", SqlDbType.Int)
Dim pMemName As New SqlParameter("@MemNAME",
SqlDbType.NVarChar, 40)
Dim pDOB As New SqlParameter("@DOB", SqlDbType.DateTime)
Dim pSSN As New SqlParameter("@SSN", SqlDbType.NVarChar,
9)
Dim pSEX As New SqlParameter("@SEX", SqlDbType.NVarChar,
1)
'Add the parameters only if the textbox value was filled
in
If Session("ssMRN") <> 0 Then
pMRN = Session("ssMRN")
cmdFillMemberSelect.Parameters.Add(pMRN)
End If
If Len(Session("ssNAME")) <> 0 Then
pMemName = Session("ssNAME")
cmdFillMemberSelect.Parameters.Add(pMemName)
End If
If Len(Session("ssDOB")) <> 0 Then
pDOB = Session("ssDOB")
cmdFillMemberSelect.Parameters.Add(pDOB)
End If
If Len(Session("ssSSN")) <> 0 Then
pSSN = Session("ssSSN")
cmdFillMemberSelect.Parameters.Add(pSSN)
End If
If Len(Session("ssSEX")) <> 0 Then
pSEX = Session("ssSEX")
cmdFillMemberSelect.Parameters.Add(pSEX)
End If
'Fill the datatable with the filtered selection
'daMembers_SQL.Fill(dsMembers, "qMemberSelect")
cmdFillMemberSelect.ExecuteNonQuery()
daMemberResults.Fill(DsMemberResults1, "vMemberResults")
DGMembers.DataMember = "vMemberResults"
DGMembers.DataSource =
DsMemberResults1.Tables("vMemberResults").DefaultView