locked
Data type mismatch in criteria expression RRS feed

  • Question

  • User-2140330002 posted

    I'm back already.

    I have a data type mismatch while inserting into a number field in an access database using a parameterized query.

    I think this should be pretty simple but I am still learning a lot.

    Sub OnBtnSendClicked(ByVal s As Object, ByVal e As EventArgs)
    		        Dim strConn As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("IndividualRates.mdb") & ";"
    
    		        Dim MyCon As New OleDbConnection(strConn)
    
    		        Dim MySqlDelete As String = "delete from problemdefinition"
    		        Dim MySqlInsert As String = "INSERT INTO problemdefinition (client, memberage, spouseage, numberchildren, County) VALUES (@client, @memberage, @spouseage, @numberchildren, @county)"
    		        'Dim MySqlInsert As String = "INSERT INTO problemdefinition (client, memberage, spouseage, numberchildren) VALUES ('" & txtName.Text & "'," & txtAge.Text & "," & txtSpouseAge.Text & "," & txtNumberChildren.Text & ")"
    
    		        Dim cmd As New OleDbCommand(MySqlDelete, MyCon)
    		        With cmd.Parameters
    		            .Add(New OleDbParameter("@client", txtName.Text))
    		            .Add(New OleDbParameter("@memberage", txtAge.Text))
    		            .Add(New OleDbParameter("@spouseage", txtSpouseAge.Text))
    		            .Add(New OleDbParameter("@numberchildren", txtNumberChildren.Text))
    		            .Add(New OleDbParameter("@county", DrpCounty.Text))
    		            '.Add(New OleDbParameter("@zipcode", DrpZip1.Text))
    		            '.Add(New OleDbParameter("@deductible", DrpDed1.Text))
    		            '.Add(New OleDbParameter("@startcoverage", DrpStartCov1.Text))
    		        End With
    		        Dim result As Integer = -1
    
    		        If MyCon.State = ConnectionState.Closed Then
    		            MyCon.Open()
    		            result = cmd.ExecuteNonQuery()
    		            MyCon.Close()
    		        End If
    
    		        If result <> -1 Then
    		            If MyCon.State = ConnectionState.Closed Then
    		                MyCon.Open()
    		                cmd.CommandText = MySqlInsert
    		                cmd.ExecuteNonQuery()
    		                MyCon.Close()
    		            End If
    		        End If
    	
    		        Response.Redirect("gbresults.aspx")
    		    End Sub


    I have some commented out as I am working one field at a time. The working fields are textboxes and the non working ones are dropdown lists. But I think it may be the field that the list is drawing from? Not sure.

    Thanks

    Tuesday, June 8, 2010 9:57 PM

Answers

  • User-2140330002 posted

    I found a partial answer to my earlier question. I configured the accessdatasource to pull from the text column and the ID column and use the ID column  for the DataValueField in the Dropdown List.

    I will keep working on this.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, June 8, 2010 10:45 PM

All replies

  • User-2140330002 posted

    I found a partial answer to my earlier question. I configured the accessdatasource to pull from the text column and the ID column and use the ID column  for the DataValueField in the Dropdown List.

    I will keep working on this.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, June 8, 2010 10:45 PM
  • User-2140330002 posted

    Ok, I actually answered all of my own questions on this one so it is resolved now.

    Not sure - do I mark this answered?

    Thanks

    (I sort of feel like I am talking to myself :)  )

    Tuesday, June 8, 2010 11:16 PM