Re: New to C# - DB question
- From: "heddy" <hedbonker@xxxxxxxxx>
- Date: 17 Aug 2006 21:26:59 -0700
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.
.
- Follow-Ups:
- Re: New to C# - DB question
- From: Marc Gravell
- Re: New to C# - DB question
- From: Steven Nagy
- Re: New to C# - DB question
- References:
- New to C# - DB question
- From: hedbonker
- Re: New to C# - DB question
- From: Steven Nagy
- New to C# - DB question
- Prev by Date: Re: Panel Height
- Next by Date: Re: TreeNode.ShowCheckBox
- Previous by thread: Re: New to C# - DB question
- Next by thread: Re: New to C# - DB question
- Index(es):