我想使用以下sql查詢從數據庫檢索數據,但這是行不通的。我正在嘗試根據輸入日期獲取數據。數據庫中的日期格式爲03/03/2013。以下查詢正確的問題。SQL查詢檢索數據使用日期作爲where子句
public DataSet OrderByDate(string date1, string date2)
{
// string connString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\\Users\\Amrit\\Desktop\\Database.accdb ;Persist Security Info=False;";
DataSet dataSet = new DataSet();
OleDbConnection oleConn = new OleDbConnection(connString);
try
{
oleConn.Open();
string sql = "SELECT Order.OrderNumber, (Customer.Title +SPACE(2)+ Customer.CustomerName) as [Customer Name], Customer.CustomerEbayname, Customer.EmailAddress, Customer.PhoneNumber, (Customer.Address1 + SPACE(2) + Customer.Address2 + SPACE(2)+ Customer.City + SPACE(2) + Customer.PostCode + SPACE(2) + Customer.Country) as Address, Order.ItemPurchased, Order.PurchasedDate, Order.TotalPrice FROM Customer INNER JOIN [Order] ON Customer.[CustomerID] = Order.[CustomerID] WHERE [PurchasedDate] BETWEEN #date1# AND #date2#"; OleDbDataAdapter dataAdapter = new OleDbDataAdapter(sql, oleConn);
dataAdapter.Fill(dataSet, "Customer");
}
catch (Exception ex)
{
MessageBox.Show("An exception has been occured\n" + ex.ToString());
Console.WriteLine(ex.ToString());
}
finally
{
oleConn.Close();
}
if (dataSet.Tables.Count <= 0)
return null;
else
return dataSet;
}
如果您的問題得到解答,請不要忘記接受。 – 2013-03-03 08:51:51