Data type mismatch in criteria expression ERROR
Code:
using (OleDbConnection dbConnection = new OleDbConnection(MainF.ConnectionString))
{//i take connectionstring from another form
dbConnection.Open();
string querySelY="select y_bool,y_sname,y_ssname,y_date from yemek where y_bool=1 and y_sname='" + lblAd.Text +"' and y_ssname='" + lblSoyad.Text +"' and y_date='" + dateTimePicker1.Value.Date.ToString() +"'";
OleDbCommand commandSelY=new OleDbCommand(querySelY,dbConnection);
OleDbDataReader readerIns=commandSelY.ExecuteReader(); //ERROR WAS HERE
if(readerIns.Read()==true)
{
MessageBox.Show("Bu güne daha önceden yemek atmışsınız !","UYARI",MessageBoxButtons.OK,MessageBoxIcon.Warning);
}
else
{
string queryInsY = "insert into yemek (y_date,y_sname,y_ssname,y_bool) values ('" + dateTimePicker1.Value.Date.ToString() + "','" + lblAd.Text + "','" + lblSoyad.Text + "',1)";
OleDbCommand commandInsY=new OleDbCommand(queryInsY,dbConnection);
if(commandInsY.ExecuteNonQuery()>0)
{
dbConnection.Close();
}
label4.Visible=true;
label5.Visible=true;
label5.Text="Yemek fişi atıldı";
MessageBox.Show("İstediğiniz tarihe yemek fişi atılmıştır.","İŞLEM TAMAM",MessageBoxButtons.OK,MessageBoxIcon.Information);
}
dbConnection.Close();
readerIns.Close();
}
by using y_date='" + dateTimePicker1.Value.Date.ToString() +"' i wanted to control if are there a record in date format in todays date.
when i don't write this the warning works but i can not record another thing in another day.
how can i fix it?