0

当我尝试输入登录时,程序正在向我发送抛出部分并写一些关于不正确的语法错误“=”的内容。

错误图片

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();
}
4

1 回答 1

0

您似乎正在尝试使用cmdSQLCommand 进行过滤。但是,您遗漏了关键字WHERE,因此出现了不正确的语法错误。它应该是这样的:

SqlCommand cmd = new SqlCommand("Select * from Personeller WHERE ID=@Id and PAROLA=@password", con)
于 2017-02-09T15:33:48.860 回答