Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/303.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/65.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# update语句的正确查询是什么?_C# - Fatal编程技术网

C# update语句的正确查询是什么?

C# update语句的正确查询是什么?,c#,C#,如何消除查询表达式“2333”erorr中字符串中的“语法错误” 试试这个代码 con.Open(); OleDbCommand dt = new OleDbCommand("UPDATE AccRec SET Quantity=@P1, Unit=@P2 ,Company=@P3, Description=@P4, Amount=@P5 Where No=@P6",con); dt.Parameters.Add("@P1", SqlDbType.VarChar); dt.Paramete

如何消除查询表达式“2333”erorr中字符串中的“语法错误”

试试这个代码

con.Open();
OleDbCommand dt = new OleDbCommand("UPDATE  AccRec SET  Quantity=@P1, Unit=@P2 ,Company=@P3, Description=@P4, Amount=@P5 Where No=@P6",con);

dt.Parameters.Add("@P1", SqlDbType.VarChar);
dt.Parameters["@P1"].Value = txtQuantity2.Text ;
dt.Parameters.Add("@P2", SqlDbType.VarChar);
dt.Parameters["@P2"].Value = txtUnit2.Text;
dt.Parameters.Add("@P3", SqlDbType.VarChar);
dt.Parameters["@P3"].Value = txtCompany2.Text;
dt.Parameters.Add("@P4", SqlDbType.VarChar);
dt.Parameters["@P4"].Value = txtDesc2.Text ;
dt.Parameters.Add("@P5", SqlDbType.VarChar);
dt.Parameters["@P5"].Value = txtAmt2.Text ;
dt.Parameters.Add("@P6", SqlDbType.VarChar);
dt.Parameters["@P6"].Value = textBox1.Text;

dt.ExecuteNonQuery();

MessageBox.Show("updated");
OleDbDataAdapter da = new OleDbDataAdapter("SELECT * From AccRec ", con);
DataTable ds = new DataTable();
da.Fill(ds);
dataGridView2.DataSource = ds;
con.Close();

请参见
其中No=5'
??你不能那样做您不应该将SQL语句连接在一起-使用参数化查询来避免SQL注入可能与@James DeanLorenzoAlimboyogue重复我刚刚添加了一个示例代码,我没有确切的数据库。所以你们可以参考我的代码来解决你们的问题。它说更新了,但我的数据库并没有任何变化,先生,即使是在数据网格上
con.Open();
OleDbCommand dt = new OleDbCommand("UPDATE  AccRec SET  Quantity=@P1, Unit=@P2 ,Company=@P3, Description=@P4, Amount=@P5 Where No=@P6",con);

dt.Parameters.Add("@P1", SqlDbType.VarChar);
dt.Parameters["@P1"].Value = txtQuantity2.Text ;
dt.Parameters.Add("@P2", SqlDbType.VarChar);
dt.Parameters["@P2"].Value = txtUnit2.Text;
dt.Parameters.Add("@P3", SqlDbType.VarChar);
dt.Parameters["@P3"].Value = txtCompany2.Text;
dt.Parameters.Add("@P4", SqlDbType.VarChar);
dt.Parameters["@P4"].Value = txtDesc2.Text ;
dt.Parameters.Add("@P5", SqlDbType.VarChar);
dt.Parameters["@P5"].Value = txtAmt2.Text ;
dt.Parameters.Add("@P6", SqlDbType.VarChar);
dt.Parameters["@P6"].Value = textBox1.Text;

dt.ExecuteNonQuery();

MessageBox.Show("updated");
OleDbDataAdapter da = new OleDbDataAdapter("SELECT * From AccRec ", con);
DataTable ds = new DataTable();
da.Fill(ds);
dataGridView2.DataSource = ds;
con.Close();