簡體   English   中英

OleDb.OleDbException 條件表達式中的數據類型不匹配

[英]OleDb.OleDbException Data type mismatch in criteria expression

我想要這樣的查詢,但出現錯誤:

錯誤

"Select * 
 From Products 
 Where (ProductName)  = '" + productName.Text + "' and  (Revise) = '" + a + "'";

我有產品名稱並在同一個表中修改為 2 個不同的列。

我有幾行產品名稱相同但修訂日期不同。 我正在嘗試選擇正確的。

con.Open();

OleDbCommand select = new OleDbCommand();
select.Connection = con;

Object revize = revizyonlar.SelectedItem;

if(revize != null)
{
    string a = revizyonlar.SelectedItem.ToString();
    System.DateTime b = Convert.ToDateTime(a);
    a = b.Date.ToShortDateString();
    a = "Select * From Products where (ProductName)  = '" + productName.Text + "' and  (Revise) = '" + a + "'";

    select.CommandText = a;
}
else
    select.CommandText = "Select * From Products Where (ProductName)  = '" + productName.Text + "'";

OleDbDataReader reader = select.ExecuteReader();

while (reader.Read())
{
}

日期表達式在 Access 中由八字形分隔,因此:

a = b.Date.ToString("yyyy'/'MM'/'dd");
a = "Select * From Products Where ProductName = '" + productName.Text + "' And Revise = #" + a + "#";

也就是說,一定要聽 Ňɏssa。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM