[英]Ms-access Syntax error (missing operator) in query expression '(Quantity * UnitPrice) ExtendedPrice'
[英]Unable to query MS Access database: “Syntax error (missing operator) in query expression”
private void button3_Click(object sender, EventArgs e)
{
if (textBox2.Text != "" & listBox1.SelectedIndex != -1)
{
string q = "update info set name='" + textBox2.Text.ToString() + "' where id " + listBox1.SelectedItem.ToString();
dosomething(q);
textBox2.Text = "";
}
}
private void dosomething(String q)
{
try {
cn.Open();
cmd.CommandText = q;
cmd.ExecuteNonQuery();
cn.Close();
loaddata();
}
每當我嘗試使用程序從MS Access更新數據時,都會出現此錯誤:
我的代碼有問題嗎?
您需要在id " + listBox1.SelectedItem.ToString();
之間的運算符。
id = " + listBox1.SelectedItem.ToString();
或您想使用的任何運算符,例如>,> =等。
您也有:
string q = "update info set name='" +
但必須是:
string q = "update info set name ='" +
注意,我在name和=符號之間添加了一個空格。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.