Specified cast is not valid

S

Shawn Berg

The following code is generating the error "Specified cast is not valid."
Can anyone help? I have commented above the line that is generating this
error. The _subject variable is a String data type.

Dim CmdText As String, CmdParams(2) As MySqlParameter

'Save email campaign to data store
CmdText = "INSERT INTO tblEmailCampaigns (subject, body, d_t) " & _
"VALUES (?, ?, ?)"

'THE LINE BELOW IS GENERATING THIS ERROR:
CmdParams(0) = New MySqlParameter("@subject", MySqlDbType.VarChar,
100).Value = _subject
CmdParams(1) = New MySqlParameter("@body", MySqlDbType.VarChar,
999999999).Value = _body
CmdParams(2) = New MySqlParameter("@d_t", MySqlDbType.Datetime).Value =
Date.Now

MySqlHelper.ExecuteNonQuery(ConfigurationSettings.AppSettings("cnTSR1"),
CmdText, CmdParams)
 
A

Alvin Bruney [Microsoft MVP]

After a cursor glance, it may be your date_time field. Comment out the other
lines of code. Just pass in one parameter at a time until you find the
culprit.

That's exactly why parameters suck. I try to avoid them whenever possible.

--
Regards
Alvin Bruney
[Shameless Author Plug]
The Microsoft Office Web Components Black Book with .NET
available at www.lulu.com/owc
 
J

Joe Fallon

Does this line have to be broken up into 2 steps?
CmdParams(0) = New MySqlParameter("@subject", MySqlDbType.VarChar,
100).Value = _subject

1. CmdParams(0) = New MySqlParameter("@subject", MySqlDbType.VarChar, 100)
2. CmdParams(0).Value = _subject
 

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

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top