specified cast is not valid

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
 
C

Cor Ligthert [MVP]

Jonefer,

I have the idea that you get a better response that you tell what code is
throwing this error.

Cor
 
G

Guest

Lo,

I almost sure the exception is thrown in one of these statments,
If Session("ssMRN") <> 0 Then
pMRN = Session("ssMRN")
cmdFillMemberSelect.Parameters.Add(pMRN)
End If

Correct to:

if Session("ssMRN") <> 0 then
pMRN.Value = Session("ssMRN")
cmdFillMemberSelect.Parameters.Add(pMRN)
end if

Milosz Skalecki
MCP, MCAD
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top