-
Jun 20th, 2015, 07:42 AM
#1
Thread Starter
Junior Member
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
-
Jun 20th, 2015, 07:56 AM
#2
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.
-
Jun 20th, 2015, 07:57 AM
#3
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.
-
Jun 20th, 2015, 08:05 AM
#4
Thread Starter
Junior Member
Re: INSERT Command Problems
Toph,
It keeps giving the same Error
-
Jun 20th, 2015, 08:11 AM
#5
Thread Starter
Junior Member
Re: INSERT Command Problems
It's something with the Date input that is wrong...the rest he saves good...
-
Jun 20th, 2015, 08:18 AM
#6
Thread Starter
Junior Member
Re: INSERT Command Problems
Found the problem...I should have put
Code:
.Parameters.AddWithValue("@p10", DateTime.Parse(Date.Now()))
This works.
Anyway thanks :-)
-
Jun 20th, 2015, 08:02 AM
#7
Thread Starter
Junior Member
Re: INSERT Command Problems
-
Jun 20th, 2015, 08:06 AM
#8
Re: INSERT Command Problems
VALUES (@p1,@p2,@p3,@p4,@p5,@p6,@p7,@p8,@p9,@p10);"
If you find my contributions helpful then rate them.
-
Jun 20th, 2015, 08:06 AM
#9
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.
-
Jun 20th, 2015, 08:33 AM
#10
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|