Saturday, November 23, 2013

Login Code Not Working

Below is how I would do it



using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.OleDb;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{
try
{
OleDbCommand comm = new OleDbCommand();
comm.CommandText = "SELECT COUNT(*) FROM Accounts WHERE username = '@username' and passcode = '@passcode';";
comm.Parameters.Add("@username", OleDbType.VarChar);
comm.Parameters.Add("@passcode", OleDbType.VarChar);

comm.Parameters["@username"].Value = txtUsername.Text;
comm.Parameters["@passcode"].Value = txtPasscode.Text;

OleDbDataReader reader = comm.ExecuteReader();

while(reader.Read())

{
this.Frame.Navigate(typeof(HomeStudent));
}
}

catch
{

}

}
}
}

No comments:

Post a Comment