51
Developer's Corner / Re: grr SQL and C#
« on: February 27, 2007, 12:54 PM »
maybe I'm mis-reading but:
string scope = null;
try
{
OleDbCommand tableSearch = connection.CreateCommand();
tableSearch.CommandText = "SELECT * FROM coursework WHERE DateDue BETWEEN '" + System.DateTime.Now.Date.ToString() + "' AND '" + scope+ "'";//sql command
will give you:
"SELECT * FROM coursework WHERE DateDue BETWEEN '2/27/2007' AND ''"
and that would give the error you describe. Perhaps you'l wnat to put in a parameter:
tableSearch.CommandText = "SELECT * FROM coursework WHERE DateDue BETWEEN getdate() AND @scope ";//sql command
and then give the parameter in code the same name.
Also FYI: "SELECT *" isn't a good practice, it's easy, but can cause problems in the future.
string scope = null;
try
{
OleDbCommand tableSearch = connection.CreateCommand();
tableSearch.CommandText = "SELECT * FROM coursework WHERE DateDue BETWEEN '" + System.DateTime.Now.Date.ToString() + "' AND '" + scope+ "'";//sql command
will give you:
"SELECT * FROM coursework WHERE DateDue BETWEEN '2/27/2007' AND ''"
and that would give the error you describe. Perhaps you'l wnat to put in a parameter:
tableSearch.CommandText = "SELECT * FROM coursework WHERE DateDue BETWEEN getdate() AND @scope ";//sql command
and then give the parameter in code the same name.
Also FYI: "SELECT *" isn't a good practice, it's easy, but can cause problems in the future.