1

When I try to insert a string value using mdmysql.Parameters.AddWithValue it generates an input format string exception. Following is the code which produces the error:

cmdmysql.Parameters.AddWithValue("@p_mode", MySqlDbType.VarChar).Value = "ccc";

I tried with varchar, string, text but nothing is working. Also if I put null in place of "ccc" then the record gets inserted into the table. The variable type for p_mode in table is varchar. What is the reason for this exception?

1
  • You are attempting to assign string to number or something like that. Commented Jan 3, 2012 at 6:33

2 Answers 2

1

The AddWithValue function takes only two inputs, 1. The parametername and 2. the value

cmdmysql.Parameters.AddWithValue("@p_mode", "ccc");

If you want to use the definition of types you must use the normal Add function:

cmdmysql.Parameters.Add("@p_mode", MySqlDbType.VarChar).Value = "ccc";

I would guess that the exception comes from your second input where you parse an MySqlDbType to the function and not the acutal value you want the returned mysqlparameter to have.

Sign up to request clarification or add additional context in comments.

3 Comments

thnx the one with addvalue is working, but the other with add is giving the same error
thnx it is working now with addwithvalue but giving same error if i use add
Can you show use some more code to set it into context and possibly also show the table structure, just the create statement for the table you insert into?
0

Try this

cmdmysql.Parameters.AddWithValue("@p_mode","ccc");

2 Comments

No! this is not answer. "CCC" is string constant.
thnx it is working now with addwithvalue but giving same error if i use add

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.