Re: New to C# - DB question




Thanks a ton, Steve. What I ended up doing for this little test was:

private void btnSubmit_Click(object sender, EventArgs e)
{
int Privelege;
string SQL;
OleDbDataReader Reader;
string sConnect = "Provider=Microsoft.Jet.OLEDB.4.0;Data
Source = G:\\Media Manager.mdb";
OleDbConnection objConnection = new OleDbConnection
(sConnect);

if (this.txtPassWd.Text.Length < 1 ||
this.txtUserID.Text.Length < 1)
{
MessageBox.Show("You MUST fill both fields in!");
return;
}

objConnection.Open();

try
{
SQL = "Select * from Users where username='" +
this.txtUserID.Text + "' AND password='" + this.txtPassWd.Text + "';";


// Find USER ID in users table
// if we find it, validate the password and set the
privledge.

OleDbCommand oMyCommand = new OleDbCommand(SQL,
objConnection);
Reader = oMyCommand.ExecuteReader();

if (Reader.HasRows)
{
// Login is good here
MessageBox.Show("Login is good");
Reader.Read();
Privelege = Reader.GetInt32(3);
}
else
{
MessageBox.Show("Login is bad");
}
}
finally
{
objConnection.Close();
//Reader.Close();
}
}

The docs said to ensure I closed the reader but the compiler complained
about it...Not sure why.

.