双AND条款

时间:2016-05-12 09:48:23

标签: c# mysql

我获得了第一个 WHERE AND 子句但第二个 AND 子句不是。

  private void LoadOrders()
    {
        con.Open();
        cmd = new SqlCommand(@"Select quo_product,quo_address
                            FROM JobQuotations
                            WHERE quotationId = @id
                            AND quo_product = @product
                            AND quo_verified = 'yes';",con);

        cmd.Parameters.AddWithValue("@id", GridView1.SelectedRow.Cells[1].Text);
        cmd.Parameters.AddWithValue("@product", GridView1.SelectedRow.Cells[2].Text);

            rdr = cmd.ExecuteReader();
            while(rdr.Read())
            {
                lblProductName.Text = rdr["quo_product"].ToString();
                lblAddress.Text = rdr["quo_Address"].ToString();
            }

        con.Close();
    }

我应该收到一个输出,其中所有quo_verified列值= ,但我还收到了一个列值=

1 个答案:

答案 0 :(得分:1)

请检查数据库中的quo_verified数据类型。由于数据类型与数据库表的列不匹配而导致的某些转换可能会导致问题。

话虽这么说,您可能希望对所有参数进行参数化,以确保C#端没有任何错误。您也可以删除分号;

private void LoadOrders()
{
    con.Open();
    cmd = new SqlCommand(@"Select quo_product,quo_address
                        FROM JobQuotations
                        WHERE quotationId = @id
                        AND quo_product = @product
                        AND quo_verified = @yes",con);

    cmd.Parameters.AddWithValue("@id", GridView1.SelectedRow.Cells[1].Text);
    cmd.Parameters.AddWithValue("@product", GridView1.SelectedRow.Cells[2].Text);
    cmd.Parameters.AddWithValue("@yes", "yes");

    rdr = cmd.ExecuteReader();
    while(rdr.Read())
    {
        lblProductName.Text = rdr["quo_product"].ToString();
        lblAddress.Text = rdr["quo_Address"].ToString();
    }
    con.Close();
}