附加信息:查询表达式'@phone no'中的语法错误(缺少运算符)。 [英] Additional information: syntax error (missing operator) in query expression '@phone no'.
本文介绍了附加信息:查询表达式'@phone no'中的语法错误(缺少运算符)。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我插入数据时,我收到这样的错误
附加信息:语法错误(缺少运算符) 查询表达式' @ Phone No '。
我的尝试:
for ( int i = 0 ; i < dataGridView21.Rows.Count; i ++)
{
OleDbCommand command = new OleDbCommand();
command.Connection = connection;
command.CommandText = @ 插入总计([Column1],[Column2],[Column3], [日期],[收据号码],[送货人],[报告],[口味],[姓名],[电话号码]
VALUES(@ Column1,@ Column2,@ Column3,@ Date,@ ReceiptNo,@ DeliveryPerson,@ Report,@ Flavours,@ Name,@ Phone No);
// values('+ dataGridView21.Rows [i] .Cells [0] .Value.ToString ()+','+ dataGridView21.Rows [i] .Cells [1] .Value.ToString()+','+ txtDisplay.Text +','+ label4.Text +', '+ label2.Text +','+ label128.Text +',+ dataGridView21.Rows [i] .Cells [0] .Value.ToString()+,'+ dataGridView21.Rows [i ] .Cells [3] .Value.ToString()+','+ dataGridView21.Rows [i] .Cells [5] .Value.ToString()+','+ dataGridView21.Rows [i]。 Cells [6] .Value.ToString()+');;
connection.Open();
for ( int j = 0 ; j < dataGridView21.Rows.Count; j ++)
{
var row = dataGridView21.Rows [j];
如果跨度> (row.IsNewRow)继续;
command.Parameters.Clear();
command.Parameters.AddWithValue( @ Column1,row.Cells [ 0 跨度>]值)。
command.Parameters.AddWithValue( @ Column2,row.Cells [ 1 跨度>]值)。
command.Parameters.AddWithValue( @ Column3,txtDisplay.Text);
command.Parameters.AddWithValue( @ Date,label4.Text);
command.Parameters.AddWithValue( @ ReceiptNo,label2.Text);
command.Parameters.AddWithValue( @ DeliveryPerson,label128.Text);
command.Parameters.AddWithValue( @ Report,row.Cells [ 0 跨度>]值)。
command.Parameters.AddWithValue( @ Flavors,row.Cells [ 3 跨度>]值)。
command.Parameters.AddWithValue( @ Name,row.Cells [ 5 跨度>]值)。
command.Parameters.AddWithValue( @ Phone No,row.Cells [ 6 跨度>]值);
command.ExecuteNonQuery();
} connection.Close();
}
// printreceiptod();
flpCategories.Enabled = false ;
flpProducts.Enabled = false ;
listBox20.Focus();
MessageBox.Show( 成功插入,dataGridView21.Rows.Count + + ITEMS,MessageBoxButtons.OK,MessageBoxIcon.Information);
listBox20.Focus();
dataGridView21.Rows.Clear();
label128.Text = Delivery;
while (listBox20.Items.Count > 0 )
{
button64.PerformClick();
}
flpCategories.Enabled = true ;
}
解决方案
您不能在变量名中添加空格。你有:
@ Report,@ Flavors,@ Name,@ Phone No) ;
。
。和
。
command.Parameters.AddWithValue( @Phone No ,row.Cells [6] .Value);
删除空格来自电话号码。
尝试替换:
VALUES ( @ Column1 , @ Column2 , @ Column3 , @ Date , @ ReceiptNo , @ DeliveryPerson , @ Report , @ Flavors , @姓名, @ Phone 否)
with
VALUES ( @ Column1 , @ Column2 ,< span class =code-sdkkeyword> @ Column3 , @ Date , @ ReceiptNo , @ DeliveryPerson , @ Report , @ Flavors , @ Name ,\ @ Phone No\ 跨度>)
when i am insert data so i am getting an error like this
Additional information: Syntax error (missing operator) in query expression '@Phone No'.
What I have tried:
for (int i = 0; i < dataGridView21.Rows.Count; i++)
{
OleDbCommand command = new OleDbCommand();
command.Connection = connection;
command.CommandText = @"insert into Total ([Column1],[Column2],[Column3],[Date],[Receipt No],[Delivery Person],[Report],[Flavours],[Name],[Phone No])
VALUES(@Column1, @Column2, @Column3, @Date, @ReceiptNo, @DeliveryPerson, @Report, @Flavours, @Name , @Phone No)";
//values('" + dataGridView21.Rows[i].Cells[0].Value.ToString() + "','" + dataGridView21.Rows[i].Cells[1].Value.ToString() + "','" + txtDisplay.Text + "','" + label4.Text + "','" + label2.Text + "','" + label128.Text + "'," + dataGridView21.Rows[i].Cells[0].Value.ToString() + ",'" + dataGridView21.Rows[i].Cells[3].Value.ToString() + "','" + dataGridView21.Rows[i].Cells[5].Value.ToString() + "','" + dataGridView21.Rows[i].Cells[6].Value.ToString() + "');";
connection.Open();
for (int j = 0; j < dataGridView21.Rows.Count; j++)
{
var row = dataGridView21.Rows[j];
if (row.IsNewRow) continue;
command.Parameters.Clear();
command.Parameters.AddWithValue("@Column1", row.Cells[0].Value);
command.Parameters.AddWithValue("@Column2", row.Cells[1].Value);
command.Parameters.AddWithValue("@Column3", txtDisplay.Text);
command.Parameters.AddWithValue("@Date", label4.Text);
command.Parameters.AddWithValue("@ReceiptNo", label2.Text);
command.Parameters.AddWithValue("@DeliveryPerson", label128.Text);
command.Parameters.AddWithValue("@Report", row.Cells[0].Value);
command.Parameters.AddWithValue("@Flavours", row.Cells[3].Value);
command.Parameters.AddWithValue("@Name", row.Cells[5].Value);
command.Parameters.AddWithValue("@Phone No", row.Cells[6].Value);
command.ExecuteNonQuery();
} connection.Close();
}
//printreceiptod();
flpCategories.Enabled = false;
flpProducts.Enabled = false;
listBox20.Focus();
MessageBox.Show("Inserted Sucessfully", dataGridView21.Rows.Count + " " + "ITEMS", MessageBoxButtons.OK, MessageBoxIcon.Information);
listBox20.Focus();
dataGridView21.Rows.Clear();
label128.Text = "Delivery";
while (listBox20.Items.Count > 0)
{
button64.PerformClick();
}
flpCategories.Enabled = true;
}
解决方案
You cannot put a space in a variable name. You have:
@Report, @Flavors, @Name , @Phone No)"; . . and . command.Parameters.AddWithValue("@Phone No", row.Cells[6].Value);
Remove the space from "Phone No".
Try to replace:
VALUES(@Column1, @Column2, @Column3, @Date, @ReceiptNo, @DeliveryPerson, @Report, @Flavours, @Name , @Phone No)
with
VALUES(@Column1, @Column2, @Column3, @Date, @ReceiptNo, @DeliveryPerson, @Report, @Flavours, @Name , \"@Phone No\")
这篇关于附加信息:查询表达式'@phone no'中的语法错误(缺少运算符)。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文