Hi,

A

Adam Maltby

Hi,

I am trying to run an update using:
Try
da.InsertCommand = New OleDbCommand
With da.InsertCommand
.CommandText = "INSERT INTO Questions(Q, A, B, C, D, CorrectAnswer, Expired, QTID) " _
& " VALUES (@Q, @A, @B, @C, @D, @CorrectAnswer, @Expired, @QTID)"
.Parameters.Add("@Q", OleDbType.VarChar, 500, "Q")
.Parameters.Add("@A", OleDbType.VarChar, 500, "A")
.Parameters.Add("@B", OleDbType.VarChar, 500, "B")
.Parameters.Add("@C", OleDbType.VarChar, 500, "C")
.Parameters.Add("@D", OleDbType.VarChar, 500, "D")
.Parameters.Add("@CorrectAnswer", OleDbType.Char, 1, "CorrectAnswer")
.Parameters.Add("@Expired", OleDbType.Boolean, 1, "Expired")
.Parameters.Add("@QTID", OleDbType.SmallInt, 2, "QTID")
.Connection = strOle
'.CommandType = CommandType.Text
End With
'process inserts.
'da.Update(dt.Select(Nothing, Nothing, DataViewRowState.Added))
Catch ex As Exception
MsgBox("Error sending Inserted updates to database." & vbCrLf & _
ex.Message, MsgBoxStyle.Critical, ex.Source)
End Try

It keeps asking me to declare the variable @Q (and then catches an ex).

Any one have any ideas?

Cheers
Adam
 
E

Earl

I'm pretty tired, but I don't see what the parameters add to this picture.
You're trying to insert @Q, @A, etc. when you should be directly inserting
Q, A, and so forth. I'm doing everything SQL, so I don't spend much time
with OleDb stuff, but I think all you need here is to straighten out the
command text and dump the parameters and you'll be in good shape.


Hi,

I am trying to run an update using:
Try
da.InsertCommand = New OleDbCommand
With da.InsertCommand
.CommandText = "INSERT INTO Questions(Q, A, B, C, D,
CorrectAnswer, Expired, QTID) " _
& " VALUES (@Q, @A, @B, @C, @D, @CorrectAnswer,
@Expired, @QTID)"
.Parameters.Add("@Q", OleDbType.VarChar, 500, "Q")
.Parameters.Add("@A", OleDbType.VarChar, 500, "A")
.Parameters.Add("@B", OleDbType.VarChar, 500, "B")
.Parameters.Add("@C", OleDbType.VarChar, 500, "C")
.Parameters.Add("@D", OleDbType.VarChar, 500, "D")
.Parameters.Add("@CorrectAnswer", OleDbType.Char, 1,
"CorrectAnswer")
.Parameters.Add("@Expired", OleDbType.Boolean, 1,
"Expired")
.Parameters.Add("@QTID", OleDbType.SmallInt, 2, "QTID")
.Connection = strOle
'.CommandType = CommandType.Text
End With
'process inserts.
'da.Update(dt.Select(Nothing, Nothing,
DataViewRowState.Added))
Catch ex As Exception
MsgBox("Error sending Inserted updates to database." &
vbCrLf & _
ex.Message, MsgBoxStyle.Critical, ex.Source)
End Try

It keeps asking me to declare the variable @Q (and then catches an ex).

Any one have any ideas?

Cheers
Adam
 
S

Sahil Malik

Nothing wrong with your code - except maybe you might be assigning a string to your connection (strOle).
What particular line are you getting the error at? try putting a breakpoint there and see if the various objects there are created by then or not.

- Sahil Malik
http://dotnetjunkies.com/weblog/sahilmalik


Hi,

I am trying to run an update using:
Try
da.InsertCommand = New OleDbCommand
With da.InsertCommand
.CommandText = "INSERT INTO Questions(Q, A, B, C, D, CorrectAnswer, Expired, QTID) " _
& " VALUES (@Q, @A, @B, @C, @D, @CorrectAnswer, @Expired, @QTID)"
.Parameters.Add("@Q", OleDbType.VarChar, 500, "Q")
.Parameters.Add("@A", OleDbType.VarChar, 500, "A")
.Parameters.Add("@B", OleDbType.VarChar, 500, "B")
.Parameters.Add("@C", OleDbType.VarChar, 500, "C")
.Parameters.Add("@D", OleDbType.VarChar, 500, "D")
.Parameters.Add("@CorrectAnswer", OleDbType.Char, 1, "CorrectAnswer")
.Parameters.Add("@Expired", OleDbType.Boolean, 1, "Expired")
.Parameters.Add("@QTID", OleDbType.SmallInt, 2, "QTID")
.Connection = strOle
'.CommandType = CommandType.Text
End With
'process inserts.
'da.Update(dt.Select(Nothing, Nothing, DataViewRowState.Added))
Catch ex As Exception
MsgBox("Error sending Inserted updates to database." & vbCrLf & _
ex.Message, MsgBoxStyle.Critical, ex.Source)
End Try

It keeps asking me to declare the variable @Q (and then catches an ex).

Any one have any ideas?

Cheers
Adam
 
M

Miha Markic [MVP C#]

Hi Adam,

Try replacing @X parameters with question marks ? in insert statement.

--
Miha Markic [MVP C#] - RightHand .NET consulting & development
miha at rthand com
www.rthand.com

Hi,

I am trying to run an update using:
Try
da.InsertCommand = New OleDbCommand
With da.InsertCommand
.CommandText = "INSERT INTO Questions(Q, A, B, C, D,
CorrectAnswer, Expired, QTID) " _
& " VALUES (@Q, @A, @B, @C, @D, @CorrectAnswer,
@Expired, @QTID)"
.Parameters.Add("@Q", OleDbType.VarChar, 500, "Q")
.Parameters.Add("@A", OleDbType.VarChar, 500, "A")
.Parameters.Add("@B", OleDbType.VarChar, 500, "B")
.Parameters.Add("@C", OleDbType.VarChar, 500, "C")
.Parameters.Add("@D", OleDbType.VarChar, 500, "D")
.Parameters.Add("@CorrectAnswer", OleDbType.Char, 1,
"CorrectAnswer")
.Parameters.Add("@Expired", OleDbType.Boolean, 1,
"Expired")
.Parameters.Add("@QTID", OleDbType.SmallInt, 2, "QTID")
.Connection = strOle
'.CommandType = CommandType.Text
End With
'process inserts.
'da.Update(dt.Select(Nothing, Nothing,
DataViewRowState.Added))
Catch ex As Exception
MsgBox("Error sending Inserted updates to database." &
vbCrLf & _
ex.Message, MsgBoxStyle.Critical, ex.Source)
End Try

It keeps asking me to declare the variable @Q (and then catches an ex).

Any one have any ideas?

Cheers
Adam
 

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