public bool checkLogin(string txtName, string txtPass, db_csDataSet dts) { DataTable dt = new DataTable(); if (dts.user.Count() > 0) { dt = dts.Tables["User"]; var q = from qds in dt.AsEnumerable() where qds.Field <string>("user_id").ToString().Trim() == txtName.ToString().Trim() && qds.Field <string>("user_password").ToString().Trim() == txtPass.ToString().Trim() select new { userID = qds.Field <string>("user_id").ToString(), userpass = qds.Field <string>("user_password").ToString() }; if (q.Count() <= 0) { return(false); } else { return(true); } } else { return(false); } }
private void button1_Click(object sender, EventArgs e) { Controler c = new Controler(); bool resLog = false; db_csDataSet ds = db_csDataSet; resLog = c.checkLogin(textBox1.Text, textBox2.Text, ds); if (resLog) { Form1 frm1 = new Form1(); frm1.ShowDialog(); frm1.Activate(); this.Hide(); this.Close(); } else { MessageBox.Show("กรุณากรอกข้อมูลให้ถูกต้อง", "ข้อมูลไม่ถูกต้อง", MessageBoxButtons.OK, MessageBoxIcon.Error); textBox1.Text = ""; textBox2.Text = ""; textBox1.Focus(); } }