2015-10-16 53 views
0
try 
{ 
    conn5.Open(); 
    OleDbCommand command = new OleDbCommand(); 
    command.Connection = conn5; 
    string query = "select * from OrderDataListTable WHERE MONTH(`DATETIME`) = dateString"; 
    command.CommandText = query; 
    reader = command.ExecuteReader(); 

將輸入月份與數據庫進行比較的正確語法是什麼?從使用月份的數據庫獲取數據

String dateString = Convert.ToString(textBox2.Text); 
DateTime month = Convert.ToDateTime(dateString + "01, 1990").Month; 

回答

0

你會使用這樣的事情,在正確格式的字符串表達式的間隔日期:

DateTime monthDate = DateTime.Parse(textBox2.Text); 
string startDate = new DateTime(monthDate.Year, monthDate.Month, 1).ToString("yyyy'/'MM'/'dd"); 
string endDate = new DateTime(monthDate.Year, monthDate.Month + 1, 1).AddDays(-1).ToString("yyyy'/'MM'/'dd"); 

然後:

string query = "select * from OrderDataListTable where [DATETIME] between #" + startDate + "# and #" + endDate + "#";