Reputation: 483
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?
Upvotes: 1
Views: 754
Reputation: 5596
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.
Upvotes: 1