【发布时间】:2021-01-18 04:39:20
【问题描述】:
我想要这样的查询,但出现错误:
"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())
{
}
【问题讨论】:
-
使用 SQL 参数和这个问题 - 以及许多其他更可怕的问题 - 将消失。自近 20 年前发布 NET SQL 以来,这就是编造 NET SQL 的错误方式
标签: c# sql ms-access oledbcommand