SqlException未处理(语法错误不正确)

时间:2017-02-09 15:27:22

标签: syntax throw unhandled-exception catch-block

当我尝试输入登录时,该程序正在向我发送投掷部分&写一些关于不正确的synxtax错误' ='。

Error image

public bool personelEntryControl(string password, int UserId)
{
    bool result = false;

    SqlConnection con = new SqlConnection(gnl.conString);
    SqlCommand cmd = new SqlCommand("Select * from Personeller ID=@Id and PAROLA=@password", con);
    cmd.Parameters.Add("@Id", SqlDbType.VarChar).Value = UserId;
    cmd.Parameters.Add("@password", SqlDbType.VarChar).Value = password;


    try
    {
        if (con.State == ConnectionState.Closed)
        {
            con.Open();
        }
        result = Convert.ToBoolean(cmd.ExecuteScalar());
    }
    catch (SqlException ex)
    {
        string hata =  ex.Message;
        throw;                      


    }

    return result;

}

public void personelGetbyInformation(ComboBox cb)
{
    cb.Items.Clear();
    bool result = false;

    SqlConnection con = new SqlConnection(gnl.conString);
    SqlCommand cmd = new SqlCommand("Select * from Personeller ", con);



    if (con.State == ConnectionState.Closed) ;
        {
            con.Open();
        }

    SqlDataReader dr = cmd.ExecuteReader();

    while (dr.Read())
    {
        cPersoneller p = new cPersoneller();
        p._PersonelId = Convert.ToInt32(dr["ID"]);
        p._PersonelGorevId = Convert.ToInt32(dr["GOREVID"]);
        p._PersonelAd = Convert.ToString(dr["AD"]);
        p._PersonelSoyad = Convert.ToString(dr["SOYAD"]);
        p._PersonelParola = Convert.ToString(dr["PAROLA"]);
        p._PersonelKullanıcıAdı = Convert.ToString(dr["KULLANICIADI"]);
        p._PersonelDurum = Convert.ToBoolean(dr["DURUM"]);
        cb.Items.Add(p);
    }
    dr.Close();
    con.Close();
}

1 个答案:

答案 0 :(得分:0)

您似乎尝试使用fn := func(args interface{}){} SQLCommand进行过滤。但是,您忽略了关键字cmd,因此语法错误不正确。它应该是这样的:

WHERE