错误文本: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();