Was trying to use a prepStatement to insert into database with multiple columns. I want the statement to adapt when I try to insert INSERT INTO prepared Statement ignoring non valid number (replacing with Null) and inserting Valid ones
string prepStatement = "INSERT INTO outright_data.sample (`date`,`last`, `lastqty`) VALUES(@date @last, @lastqty)";
_prepStmt.CommandText = prepStatement;
if (frun)
{
_prepStmt.Parameters.AddWithValue("@date", datetime_var);
_prepStmt.Parameters.AddWithValue("@last", last_var);
_prepStmt.Parameters.AddWithValue("@lastqty", lastQty_var);
_prepStmt.Prepare();
frun = false;
}
else
{
_prepStmt.Parameters["@date"].Value = datetime_var;
_prepStmt.Parameters["@last"].Value = last_var;
_prepStmt.Parameters["@lastqty"].Value = lastQty_var;
}
i++;
_counter += _prepStmt.ExecuteNonQuery();
Imagine that lastQty_var variable is not accepted in the lastQty
(but the datetime_var and last_var are accepted into their columns) column of mySQL table. When I execute, it raises an exception and stops the code. Is there a way for it to insert the other values and replace the invalid value (lastQty_var) by NULL in the database?
I tried validating the variable using is
(problem is, the variable is a double on C#, but not accepted in my double column, so validating in C# types is not a big help);
I wanted to avoid big validating structures, since speed is very important in the whole proccess.
Any advice?
Thanks,
Tomas