hi, i'm using the code below to insert data into an access db but keep gettin the error "Datatype mismatch in criteria expression"

total = Integer.Parse(txtMonth.Text) * Integer.Parse(rent.Text)
                Com.CommandText = "Insert into Report Values (?,?,?,?,?,?,?,?,?, NOW())"
                With Com.Parameters
                    .Add("@ID", OleDbType.Integer).Value = CID
                    .Add("@Tenant", OleDbType.VarChar).Value = cboTenant.Text
                    .Add("@type", OleDbType.VarChar).Value = housetype.Text
                    .Add("@loc", OleDbType.VarChar).Value = locate.Text
                    .Add("@rent", OleDbType.Currency).Value = rent.Text
                    .Add("@months", OleDbType.Integer).Value = txtMonth.Text
                    .Add("@total", OleDbType.Currency).Value = total
                    .Add("@mop", OleDbType.VarChar).Value = cbomop.Text
                    .Add("@stat", OleDbType.VarChar).Value = stat



                End With
                Com.ExecuteNonQuery()
                Com.Parameters.Clear()

                Review.Show()

Recommended Answers

All 2 Replies

hi, i'm using the code below to insert data into an access db but keep gettin the error "Datatype mismatch in criteria expression"

total = Integer.Parse(txtMonth.Text) * Integer.Parse(rent.Text)
                Com.CommandText = "Insert into Report Values (?,?,?,?,?,?,?,?,?, NOW())"
                With Com.Parameters
                    .Add("@ID", OleDbType.Integer).Value = CID
                    .Add("@Tenant", OleDbType.VarChar).Value = cboTenant.Text
                    .Add("@type", OleDbType.VarChar).Value = housetype.Text
                    .Add("@loc", OleDbType.VarChar).Value = locate.Text
                    .Add("@rent", OleDbType.Currency).Value = rent.Text
                    .Add("@months", OleDbType.Integer).Value = txtMonth.Text
                    .Add("@total", OleDbType.Currency).Value = total
                    .Add("@mop", OleDbType.VarChar).Value = cbomop.Text
                    .Add("@stat", OleDbType.VarChar).Value = stat



                End With
                Com.ExecuteNonQuery()
                Com.Parameters.Clear()

                Review.Show()

Hi

Have you tried incrementally inserting the records i.e first try with 1 fields, then 2 fields and so on that way you will be able 2 knw. which expression is raising the error. It would also help if I knew the design of the table u r trying to save data to.

In your parameters you have several different datatypes defined. However each of the values that you are passing to them is text. You need to convert and assign the proper datatype values to these parameters.

Ex:

'.Add("@months", OleDbType.Integer).Value = txtMonth.Text
    .Add("@months", OleDbType.Integer).Value = CInt(txtMonth.Text)
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.