none
Datenbankabfrage bei Login RRS feed

  • Frage

  • Hi,

     

    ich habe da mal eine Frage: bei einem Login in ein Programm verwende ich folgende LINQ-Abfrage um zu checken, ob ein Benutzer existiert und ihn dann einzuloggen:

     

    private void LoginUser()

    {

    string strBenutzer = "";

    string strPasswort = "";

    strBenutzer = benutzerTextBox.Text;

    strPasswort = passwortTextBox.Text;

    try

    {

    var loginQry = from b in db.Benutzer

    where b.Benutzername == strBenutzer

    && b.Passwort == strPasswort

    select b;

     

    foreach (var b in loginQry)

    {

    string strFensterText = "";

    string strVorname = b.Vorname.ToString();

    string strName = b.Name.ToString();

    frmHaupt objHaupt = new frmHaupt();

    objHaupt.MdiParent = (frmMain)this.Tag;

    objHaupt.Tag = this.Tag;

    objHaupt.WindowState = FormWindowState.Maximized;

    strFensterText = objHaupt.Text;

    objHaupt.Text = strFensterText + " - Hallo " + strVorname + " " + strName + "!";

    objHaupt.Show();

    this.Close();

    }

    }

    catch (Exception)

    {

    throw;

    }

    }

     

    Ich wollte eigentlich direkt nach der LINQ-Abfrage checken, ob meine "loginQry" sozusagen "leer" ist, genau das bekomme ich aber irgendwie nicht hin... Wahrscheinlich stehe ich da total auf dem Schlauch...?! Tausend Dank im Voraus für Eure Hilfe!

     

    Gruß

    Marcus

    Sonntag, 1. Juni 2008 06:25