Hi!
I would like to filter dates with two values once (dates + days + name).
But I receive this error message: "not sufficient parameters..."
conn.Open();
OleDbCommand cmd = conn.CreateCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = "select * from personal where (date between ? and ?) and days = ? and (name = ?)";
var param1 = new OleDbParameter("@StartDate", OleDbType.Date);
var param2 = new OleDbParameter("@EndDate", OleDbType.Date);
var param3 = new OleDbParameter("@name", OleDbType.VarChar);
var param4 = new OleDbParameter("@days", OleDbType.VarChar);
param1.Value = dataStart.Value.Date;
param2.Value = dataFinal.Value.Date;
param3.Value = days.Text;
param4.Value = name.Text;
if (dataStart.Value <= dataFinal.Value)
{
cmd.Parameters.Add(param1);
cmd.Parameters.Add(param2);
}
else
{
cmd.Parameters.Add(param2);
cmd.Parameters.Add(param1);
}
cmd.Parameters.Add(param3);
cmd.ExecuteNonQuery();
DataTable dt = new DataTable();
OleDbDataAdapter da = new OleDbDataAdapter(cmd);
da.Fill(dt);
conn.Close();
dgvRpt2.DataSource = dt;
}
VulpesPosted Jan 23, 2015, 12:16 PM
ISNULL(?)
However, if you're referring to the third parameter both as it stands and within this expression then you'll need to add it to the parameter collection again.
Remember that OleDb associates the parameters in the collection with the '?'s in the query in exactly the same order.
Mfwamba TshimangaPosted Jan 23, 2015, 12:04 PM
But tell me Vulpes. The textbox "days" I put a number (for example 1). Then if I need to say "when is null". What can I write as code. But its bugging.
For instance her: param3 param3.IsNullable();
Doesnt works!
Mfwamba TshimangaPosted Jan 23, 2015, 11:51 AM
Mfwamba TshimangaPosted Jan 23, 2015, 11:49 AM
the parameters are wrong or not enough.
VulpesPosted Jan 23, 2015, 11:48 AM