0

错误文本:Incorrect syntax near '='.

我的代码中有什么错误?我如何正确选择此代码以确定是否找到

这是我所有的代码,请检查一下

它检查我的值并更新一些它或插入

sssssssssssssssssssssssssssssssssssssssssssssssss

  //Test For Insert Duplicate Row
                        int tst = 0;

                        SqlCommand cmd = new SqlCommand("Select Count(*) From Product Where ProdCode=@CodeVar And ProdName= @NameVar And BuyPrice=@PriceVar",conn);
                        cmd.Parameters.Add("@CodeVar", SqlDbType.Int).Value = Convert.ToDouble(dataGridView1.Rows[x].Cells[1].Value);
                        cmd.Parameters.Add("@NameVar", SqlDbType.NVarChar).Value = dataGridView1.Rows[x].Cells[2].Value;
                        cmd.Parameters.Add("@PriceVar", SqlDbType.Money).Value = Convert.ToDouble(dataGridView1.Rows[x].Cells[4].Value);
                        cmd.CommandType = CommandType.Text;
                        conn.Open();
                       SqlDataReader reader= cmd.ExecuteReader();
                        if(reader.Read())
                        {

                            if (Convert.ToInt16(reader[0]) > 0)
                            {
                                tst = 1;
                            }
                        }
                        reader.Close();
                        conn.Close();
                        // Test For Same Row But Anthor Code
                        cmd.CommandText = "Select Count(*) From Product Where ProdName=@PName And BuyPrice=@BPrice And Not ProdCode  = @Pcode And ProdCode BETWEEN @SCode And @SCode+2000";
                        cmd.CommandType = CommandType.Text;
                        cmd.Parameters.Add("@PName",SqlDbType.NVarChar).Value = dataGridView1.Rows[x].Cells[2].Value ;
                        cmd.Parameters.Add("@BPrice", SqlDbType.Money).Value = Convert.ToDouble(dataGridView1.Rows[x].Cells[5].Value);
                        cmd.Parameters.Add("@Pcode",SqlDbType.Int).Value =  Convert.ToInt32(dataGridView1.Rows[x].Cells[1].Value);
                        cmd.Parameters.Add("@SCode", SqlDbType.Decimal).Value = Convert.ToDecimal(label10.Text);
                        cmd.CommandType = CommandType.Text;
                        conn.Open();
                      reader = cmd.ExecuteReader();
                        if(reader.Read())
                        {
                            if(Convert.ToInt16(reader[0])>0)
                            {
                                tst = 2;
                            }

                        }
                        reader.Close();
                        conn.Close();
                        cmd.CommandText = "Select Count(*) From Product Where ProdCode = @CodeVar1 ";
                        cmd.Parameters.Add("@CodeVar1", SqlDbType.Int).Value = Convert.ToInt32(dataGridView1.Rows[x].Cells[1].Value);
                        cmd.CommandType = CommandType.Text;
                        conn.Open();
                         reader= cmd.ExecuteReader();
                        if (reader.Read())
                        {

                            if (Convert.ToInt16(reader[0]) > 0 && tst == 0)
                            {
                                MessageBox.Show("الأكواد باللون الأحمر خاصة احد الأصناف ..!");
                                dataGridView1.Rows[x].Cells[1].Style = redcell;
                                return;
                            }
                        }
                        reader.Close();
                        conn.Close();
4

3 回答 3

3

您应该尝试ProdCode Not = @PcodeProdCode != @PcodeorProdCode <> @Pcode或替换Not ProdCode = @Pcode

所有在 TSQL 中都应该是有效的。

于 2013-02-21T11:14:48.703 回答
2

改变

and ProdCode Not = @Pcode

and not ProdCode = @Pcode
于 2013-02-21T11:15:11.253 回答
1

您需要将ProdCode Not = @Pcodesql 命令中的ProdCode <> @Pcode

于 2013-02-21T11:15:26.787 回答