Data type mismatch in criteria expression ERROR

This is a discussion on Data type mismatch in criteria expression ERROR within the C# Programming forums, part of the General Programming Boards category; 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 ...

  1. #1
    Registered User Aga^^'s Avatar
    Join Date
    Aug 2008
    Posts
    71

    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?

  2. #2
    the hat of redundancy hat nvoigt's Avatar
    Join Date
    Aug 2001
    Location
    Hannover, Germany
    Posts
    3,138
    The date format your sql datasource expects to get and the date format you supply probably don't match. The line you marked will throw an exception, which has more information about what went wrong. Catch it.
    hth
    -nv

    She was so Blonde, she spent 20 minutes looking at the orange juice can because it said "Concentrate."

    When in doubt, read the FAQ.
    Then ask a smart question.

  3. #3
    Registered User Aga^^'s Avatar
    Join Date
    Aug 2008
    Posts
    71
    thats it , it is allright ! thanks nvoigt

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Another syntax error
    By caldeira in forum C Programming
    Replies: 31
    Last Post: 09-05-2008, 01:01 AM
  2. Post...
    By maxorator in forum C++ Programming
    Replies: 12
    Last Post: 10-11-2005, 08:39 AM
  3. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  4. Learning OpenGL
    By HQSneaker in forum C++ Programming
    Replies: 7
    Last Post: 08-06-2004, 08:57 AM
  5. Stupid compiler errors
    By ChrisEacrett in forum C++ Programming
    Replies: 9
    Last Post: 11-30-2003, 04:44 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21