2
Answers

Problem with retrieving data - C#&MS Access

Neven

Neven

14y
2.3k
1
Hello, 

I have minor problem with retrieving data from MS ACCESS database with SELECT - WHERE statement. I want to get certain rows based on date. 

Here is the code:
 	    OleDbConnection con = new OleDbConnection(conn.ConnString.ToString());
            con.Open();
            OleDbCommand cmd = new OleDbCommand("SELECT Price FROM Warehouse WHERE Date = #"+date,con);
            OleDbDataReader reader = cmd.ExecuteReader();

            while (reader.Read())
            {
                txtProba.AppendText(reader.GetValue(0).ToString() + "\n");
            }


            con.Close();

This part of code works but only without WHERE clause. With WHERE clause i get this error:

Syntax error in date in query expression 'Datum = #3.4.2010.'

3.4.2010 is value of date variable above in code. I don't know what to anymore i tried without #, but this doesn't work too...
Please give me a hand....
Thanks in advance.... Neven

Answers (2)