Results 1 to 10 of 10

Thread: INSERT Command Problems

Hybrid View

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jun 2015
    Posts
    24

    INSERT Command Problems

    Hi,

    I can't figure out why I get the error "datatype mismatch in criteria expression"

    This is my script:
    Code:
     Using meldingcmd As OleDbCommand = New OleDbCommand
                Make_con()
                With meldingcmd
                    .Parameters.Clear()
                    .Connection = con
                    .CommandText = "INSERT INTO Meldingen (Weg_ID,Onderdeel,Dringendheid,Beginlat,Beginlong,Eindlat,Eindlong,Afstand,Opmerkingen,Datum) VALUES (?,?,?,?,?,?,?,?,?,?);"
                    .Parameters.AddWithValue("@p1", Convert.ToInt32(current_weg_Id))
                    .Parameters.AddWithValue("@p2", Onderdeel_CBX.Text)
                    .Parameters.AddWithValue("@p3", Dringendheid_CBX.Text)
                    .Parameters.AddWithValue("@p4", Convert.ToDecimal(BeginLAT_T.Text))
                    .Parameters.AddWithValue("@p5", Convert.ToDecimal(BeginLONG_T.Text))
                    .Parameters.AddWithValue("@p6", Convert.ToDecimal(EindLAT_T.Text))
                    .Parameters.AddWithValue("@p7", Convert.ToDecimal(EindLONG_T.Text))
                    .Parameters.AddWithValue("@p8", Convert.ToDecimal(Afstand_T.Text))
                    .Parameters.AddWithValue("@p9", Melding_opmerking_T.Text)
                    .Parameters.AddWithValue("@p10", Date.Now())
                    .ExecuteNonQuery()
                End With
                con.Close()
            End Using
    And my fields have been defined in Access as
    current_weg_ID = Number, Long Integer
    Onderdeel = Text
    Dringendheid = Text
    Beginlat,Beginlong,Eindlat,Eindlong,Afstand = Number, Decimal
    Opmerkingen = Memo
    Datum = Date/Time, Standard notation.

    Can anybody help me...it's driving me nuts at this moment :-)

    Grtz and thanks

  2. #2
    Fanatic Member Toph's Avatar
    Join Date
    Oct 2014
    Posts
    655

    Re: INSERT Command Problems

    Try this.

    Code:
    Using meldingcmd As OleDbCommand = New OleDbCommand
                Make_con()
                With meldingcmd
                    .Parameters.Clear()
                    .Connection = con
                    .CommandText = "INSERT INTO Meldingen (Weg_ID,Onderdeel,Dringendheid,Beginlat,Beginlong,Eindlat,Eindlong,Afstand,Opmerkingen,Datum) VALUES (@p1,p2,p3,p4,p5,p6,p7,p8,p9,p10);"
    
                    .Parameters.AddWithValue("@p1", Convert.ToInt32(current_weg_Id))
                    .Parameters.AddWithValue("@p2", Onderdeel_CBX.Text)
                    .Parameters.AddWithValue("@p3", Dringendheid_CBX.Text)
                    .Parameters.AddWithValue("@p4", Convert.ToDecimal(BeginLAT_T.Text))
                    .Parameters.AddWithValue("@p5", Convert.ToDecimal(BeginLONG_T.Text))
                    .Parameters.AddWithValue("@p6", Convert.ToDecimal(EindLAT_T.Text))
                    .Parameters.AddWithValue("@p7", Convert.ToDecimal(EindLONG_T.Text))
                    .Parameters.AddWithValue("@p8", Convert.ToDecimal(Afstand_T.Text))
                    .Parameters.AddWithValue("@p9", Melding_opmerking_T.Text)
                    .Parameters.AddWithValue("@p10", Date.Now())
                    .ExecuteNonQuery()
                End With
                con.Close()
            End Using
    If you find my contributions helpful then rate them.

  3. #3
    Fanatic Member Toph's Avatar
    Join Date
    Oct 2014
    Posts
    655

    Re: INSERT Command Problems

    Also, you might not need to use Convert.ToDecimal, because when you paramterize your queries, they get converted to the right data type automatically.
    If you find my contributions helpful then rate them.

  4. #4

    Thread Starter
    Junior Member
    Join Date
    Jun 2015
    Posts
    24

    Re: INSERT Command Problems

    Toph,
    It keeps giving the same Error

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Jun 2015
    Posts
    24

    Re: INSERT Command Problems

    It's something with the Date input that is wrong...the rest he saves good...

  6. #6

    Thread Starter
    Junior Member
    Join Date
    Jun 2015
    Posts
    24

    Re: INSERT Command Problems

    Found the problem...I should have put
    Code:
    .Parameters.AddWithValue("@p10", DateTime.Parse(Date.Now()))
    This works.
    Anyway thanks :-)

  7. #7

    Thread Starter
    Junior Member
    Join Date
    Jun 2015
    Posts
    24

    Re: INSERT Command Problems

    Ok, I'll try that

  8. #8
    Fanatic Member Toph's Avatar
    Join Date
    Oct 2014
    Posts
    655

    Re: INSERT Command Problems

    VALUES (@p1,@p2,@p3,@p4,@p5,@p6,@p7,@p8,@p9,@p10);"
    If you find my contributions helpful then rate them.

  9. #9
    Fanatic Member Toph's Avatar
    Join Date
    Oct 2014
    Posts
    655

    Re: INSERT Command Problems

    Oops, add @p1, @p2, @p3 and so on. I forgot to include the @ sign in the Insert Statement
    If you find my contributions helpful then rate them.

  10. #10
    Fanatic Member Toph's Avatar
    Join Date
    Oct 2014
    Posts
    655

    Re: INSERT Command Problems

    No problem , I knew you'd work something out
    If you find my contributions helpful then rate them.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width