Object must implement IConvertible

A few days ago, some Experts on here helped me with this thread:


I accepted the answer that pertained to security within  my SQL code.  Once again I am in need of using the same methods and have encountered this error with attached code:

Object must implement IConvertible

In reading up, I found a blog that talks about you can't pass the .TEXT property to a param, but this doesn't make any sense because it did work.  Any guidance is much appreciated.

SqlConnection cn = new SqlConnection(System.Configuration.ConfigurationSettings.AppSettings["MSSQLConnectionString"]);
                SqlCommand cmd = cn.CreateCommand();
                    cmd.CommandText = "INSERT INTO Items(Title,Description,Cost,Char01,Char02,Char03,Char04,Char05,CharLBL01,CharLBL02,CharLBL03,CharLBL04,CharLBL05) VALUES (@Title,@Description,@Cost,@Char01,@Char02,@Char03,@Char04,@Char05,@CharLBL01,@CharLBL02,@CharLBL03,@CharLBL04,@CharLBL05)";
                    cmd.Parameters.AddWithValue("@Title", txtTitle.Text).DbType = DbType.String;
                    cmd.Parameters.AddWithValue("@Description", txtDescription.Text).DbType = DbType.String;
                    cmd.Parameters.AddWithValue("@Cost", txtCost.Text).DbType = DbType.String;
                    cmd.Parameters.AddWithValue("@Char01", txtChar01.Text).DbType = DbType.String;
                    cmd.Parameters.AddWithValue("@Char02", txtChar02.Text).DbType = DbType.String;
                    cmd.Parameters.AddWithValue("@Char03", txtChar03.Text).DbType = DbType.String;
                    cmd.Parameters.AddWithValue("@Char04", txtChar04.Text).DbType = DbType.String;
                    cmd.Parameters.AddWithValue("@Char05", txtChar05).DbType = DbType.String;
                    cmd.Parameters.AddWithValue("@CharLBL01", txtCharLBL01.Text).DbType = DbType.String;
                    cmd.Parameters.AddWithValue("@CharLBL02", txtCharLBL02.Text).DbType = DbType.String;
                    cmd.Parameters.AddWithValue("@CharLBL03", txtCharLBL03.Text).DbType = DbType.String;
                    cmd.Parameters.AddWithValue("@CharLBL04", txtCharLBL04.Text).DbType = DbType.String;
                    cmd.Parameters.AddWithValue("@CharLBL05", txtCharLBL05.Text).DbType = DbType.String;

Open in new window

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

AndyAinscowFreelance programmer / ConsultantCommented:
does changing to txtTitle.Text.ToString() (and all the others) help cure it ?
AndyAinscowFreelance programmer / ConsultantCommented:
ps. I assume that txtTitle ... are edit boxs on the form to enter values.

Also does the error message come on just one line or all the AddWithValue lines ?

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Carl TawnSystems and Integration DeveloperCommented:
Have you just missed ".Text" in this line, or is is a typo:

    cmd.Parameters.AddWithValue("@Char05", txtChar05).DbType = DbType.String;
chrisryhalAuthor Commented:
You know what it was (grin) look at my line for Char05, i didn't specify the .TEXT property.  Ok, I feel like an idiot.  Thanks for the help.
chrisryhalAuthor Commented:
Carl, you beat me to it as i was typing lol
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.