简体   繁体   中英

Incorrext syntax near '=' error in SQL select query

Error Text : Incorrect syntax near '='.

What is the error in my Code? How I Can Select It right this code to sure if this found or not

its All my Code Plz Check It

its to check my value and update some it or insert

ssssssssssssssssssssssssssssssssssssssssssssssssssssssss

  //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();

You should try to replace ProdCode Not = @Pcode with ProdCode != @Pcode or ProdCode <> @Pcode or Not ProdCode = @Pcode .

All should be valid in TSQL.

change

and ProdCode Not = @Pcode

to

and not ProdCode = @Pcode

您需要使用ProdCode <> @Pcode替换sql命令中的ProdCode Not = @Pcode ProdCode <> @Pcode

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM