EDN Admin
Well-known member
using System;<br/>
using System.Collections.Generic;<br/>
using System.ComponentModel;<br/>
using System.Data;<br/>
using System.Drawing;<br/>
using System.Linq;<br/>
using System.Text;<br/>
using System.Threading.Tasks;<br/>
using System.Windows.Forms;<br/>
using System.Data.OleDb;<br/>
using System.IO;<br/>
using System.Security.Cryptography;<br/>
<br/>
namespace Data<br/>
{<br/>
public partial class frmLogin : Form<br/>
{<br/>
public frmLogin()<br/>
{<br/>
InitializeComponent();<br/>
}<br/>
private static DataTable LookupUser(string UserName)<br/>
{<br/>
string query = "select password from User where username = @username";<br/>
DataTable result = new DataTable();<br/>
using (OleDbConnection con = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=d:database1.accdb;Persist Security Info=False;"))<br/>
{<br/>
con.Open();<br/>
using (OleDbCommand cmd = new OleDbCommand(query, con))<br/>
{<br/>
cmd.Parameters.Add("@username", OleDbType.VarChar).Value = UserName;<br/>
using (OleDbDataReader dr = cmd.ExecuteReader()) ---------------------------> syntax error from clause <br/>
{<br/>
result.Load(dr);<br/>
}<br/>
}<br/>
}<br/>
return result;<br/>
<br/>
}<br/>
private static DataTable LookupUsersa(string Password)<br/>
{<br/>
string query = "select password from user where username = @password";<br/>
DataTable result = new DataTable();<br/>
using (OleDbConnection con = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=Eatabase1accdb;Persist Security Info=False"))<br/>
{<br/>
con.Open();<br/>
using (OleDbCommand cmd = new OleDbCommand(query, con))<br/>
{<br/>
cmd.Parameters.Add("@password", OleDbType.VarChar).Value = Password;<br/>
using (OleDbDataReader dr = cmd.ExecuteReader())<br/>
{<br/>
result.Load(dr);<br/>
}<br/>
}<br/>
}<br/>
return result;<br/>
}<br/>
<br/>
private void frmLogin_Load(object sender, EventArgs e)<br/>
{<br/>
<br/>
}<br/>
<br/>
private void button1_Click(object sender, EventArgs e)<br/>
{<br/>
if (string.IsNullOrEmpty(textBoxUserame.Text))<br/>
{<br/>
//Focus box before showing a message<br/>
textBoxUserame.Focus();<br/>
MessageBox.Show("Enter your username", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);<br/>
//Focus again afterwards, sometimes people double click message boxes and select another control accidentally<br/>
textBoxUserame.Focus();<br/>
return;<br/>
}<br/>
else if (string.IsNullOrEmpty(textBoxPassword.Text))<br/>
{<br/>
textBoxPassword.Focus();<br/>
MessageBox.Show("Enter your password", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);<br/>
textBoxPassword.Focus();<br/>
return;<br/>
}<br/>
using (DataTable dt = LookupUser(textBoxUserame.Text))<br/>
{<br/>
if (dt.Rows.Count == 0)<br/>
{<br/>
textBoxUserame.Focus();<br/>
MessageBox.Show("Invalid username.", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);<br/>
textBoxUserame.Focus();<br/>
return;<br/>
}<br/>
using (DataTable dt1 = LookupUsersa(textBoxPassword.Text))<br/>
if (dt1.Rows.Count == 0)<br/>
{<br/>
textBoxPassword.Focus();<br/>
MessageBox.Show("Invalid P.", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);<br/>
textBoxPassword.Focus();<br/>
return;<br/>
}<br/>
else<br/>
{<br/>
<br/>
MessageBox.Show("Login");<br/>
<br/>
}<br/>
}<br/>
}<br/>
}<br/>
}<br/>
<br/>
View the full article
using System.Collections.Generic;<br/>
using System.ComponentModel;<br/>
using System.Data;<br/>
using System.Drawing;<br/>
using System.Linq;<br/>
using System.Text;<br/>
using System.Threading.Tasks;<br/>
using System.Windows.Forms;<br/>
using System.Data.OleDb;<br/>
using System.IO;<br/>
using System.Security.Cryptography;<br/>
<br/>
namespace Data<br/>
{<br/>
public partial class frmLogin : Form<br/>
{<br/>
public frmLogin()<br/>
{<br/>
InitializeComponent();<br/>
}<br/>
private static DataTable LookupUser(string UserName)<br/>
{<br/>
string query = "select password from User where username = @username";<br/>
DataTable result = new DataTable();<br/>
using (OleDbConnection con = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=d:database1.accdb;Persist Security Info=False;"))<br/>
{<br/>
con.Open();<br/>
using (OleDbCommand cmd = new OleDbCommand(query, con))<br/>
{<br/>
cmd.Parameters.Add("@username", OleDbType.VarChar).Value = UserName;<br/>
using (OleDbDataReader dr = cmd.ExecuteReader()) ---------------------------> syntax error from clause <br/>
{<br/>
result.Load(dr);<br/>
}<br/>
}<br/>
}<br/>
return result;<br/>
<br/>
}<br/>
private static DataTable LookupUsersa(string Password)<br/>
{<br/>
string query = "select password from user where username = @password";<br/>
DataTable result = new DataTable();<br/>
using (OleDbConnection con = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=Eatabase1accdb;Persist Security Info=False"))<br/>
{<br/>
con.Open();<br/>
using (OleDbCommand cmd = new OleDbCommand(query, con))<br/>
{<br/>
cmd.Parameters.Add("@password", OleDbType.VarChar).Value = Password;<br/>
using (OleDbDataReader dr = cmd.ExecuteReader())<br/>
{<br/>
result.Load(dr);<br/>
}<br/>
}<br/>
}<br/>
return result;<br/>
}<br/>
<br/>
private void frmLogin_Load(object sender, EventArgs e)<br/>
{<br/>
<br/>
}<br/>
<br/>
private void button1_Click(object sender, EventArgs e)<br/>
{<br/>
if (string.IsNullOrEmpty(textBoxUserame.Text))<br/>
{<br/>
//Focus box before showing a message<br/>
textBoxUserame.Focus();<br/>
MessageBox.Show("Enter your username", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);<br/>
//Focus again afterwards, sometimes people double click message boxes and select another control accidentally<br/>
textBoxUserame.Focus();<br/>
return;<br/>
}<br/>
else if (string.IsNullOrEmpty(textBoxPassword.Text))<br/>
{<br/>
textBoxPassword.Focus();<br/>
MessageBox.Show("Enter your password", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);<br/>
textBoxPassword.Focus();<br/>
return;<br/>
}<br/>
using (DataTable dt = LookupUser(textBoxUserame.Text))<br/>
{<br/>
if (dt.Rows.Count == 0)<br/>
{<br/>
textBoxUserame.Focus();<br/>
MessageBox.Show("Invalid username.", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);<br/>
textBoxUserame.Focus();<br/>
return;<br/>
}<br/>
using (DataTable dt1 = LookupUsersa(textBoxPassword.Text))<br/>
if (dt1.Rows.Count == 0)<br/>
{<br/>
textBoxPassword.Focus();<br/>
MessageBox.Show("Invalid P.", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);<br/>
textBoxPassword.Focus();<br/>
return;<br/>
}<br/>
else<br/>
{<br/>
<br/>
MessageBox.Show("Login");<br/>
<br/>
}<br/>
}<br/>
}<br/>
}<br/>
}<br/>
<br/>
View the full article