Insert Problem

J

Joe Delphi

Hi,

I am attempting to do an INSERT operation using the OleDBCommand
object. I am receiving this error message:

"Object must implement IConvertible"

Here is the part of my code where the error occurs:

Dim cmdInsert As System.Data.OleDb.OleDbCommand
cmdInsert = Me.daChangeRequests.InsertCommand
With cmdInsert
.Parameters(0).Value = Me.txtTitle.Text
.Parameters(1).Value = Me.txtDescription.Text
.Parameters(2).Value = Me.ddlstPriority.SelectedItem
.Parameters(3).Value = Me.ddlstStatus.SelectedItem
.Parameters(4).Value = Me.ddlstSubBy.SelectedItem
.Parameters(5).Value = Today
.Parameters(6).Value = Me.txtNotes.Text
.Parameters(7).Value = Me.ddlstStatus.SelectedItem
.Parameters(8).Value = Me.txtDateFixed.Text
End With

'Now INSERT the record into the database, and let the user
'know if something went wrong with the INSERT.

cnChangeRequests.Open()

Try
cmdInsert.ExecuteNonQuery()
Me.lblSaved.ForeColor = White
Me.lblSaved.Text = "CR successfully saved."
Catch
Me.lblSaved.ForeColor = Red
Me.lblSaved.Text = Err.Description
cnChangeRequests.Close()
Exit Sub
End Try

cnChangeRequests.Close()



Can anyone tell me what I am doing wrong?

JD
 
M

Marina Levit [MVP]

It would be quite helpful if you told us which line actually causes the
error.

My guess is, it is one of the lines where you are assigning parameter
values. You are assigning SelectedItem, which is not the expected type and
cannot be converted to the expected type. Do yourself a favor and always
use Option Strict On, if this is the case.
 
M

MSDN

This is your problem: Value = Me.ddlstPriority.SelectedItem
might want

..Parameter(x).Value = Me.ddlstPriority.SelectedItem.value
or
..Parameter(x).Value = Value = Me.ddlstPriority.SelectedItem.text

SA
 

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