Building ADO.net Connected ASP.Net page with C#
Building ADO.net Connected ASP.Net page with C#
Hey guys..
I have problem. The following is a method I call to have a users credentials checked at the start of my page. When I click the button that calls this method however, it gives me an error stating : "No value given for one or more required parameters"
public void doLogin()
{
string UserN = "";
string PassW = "";
try
{
// Create OleDbConnection for login purposes. The while loop sets the vars and the if statement checks it.
string readCommand = "SELECT * FROM Jobs WHERE Username='" + UsernameTextbox.Text + "'";
OleDbConnection loginConnection = new OleDbConnection();
loginConnection.ConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Inetpub\wwwroot\JobNet\Database\jobs.mdb;Persist Security Info=False";
OleDbCommand loginCommand = new OleDbCommand(readCommand,loginConnection);
loginConnection.Open();
OleDbDataReader loginR = loginCommand.ExecuteReader();
while (loginR.Read())
{
UserN = loginR["Username"].ToString();
PassW = loginR["Password"].ToString();
if ((UsernameTextbox.Text == UserN) && (PasswordTextBox.Text == PassW))
{
Label3.Text = "Success!";
}
}
loginConnection.Close();
}
catch (OleDbException exc)
{
Label3.Text = "Error : " + exc.Message;
}
}
WHAT AM I MISSING???
I'm using VS.Net 2003 and .Net Framework version 1.1
I have problem. The following is a method I call to have a users credentials checked at the start of my page. When I click the button that calls this method however, it gives me an error stating : "No value given for one or more required parameters"
public void doLogin()
{
string UserN = "";
string PassW = "";
try
{
// Create OleDbConnection for login purposes. The while loop sets the vars and the if statement checks it.
string readCommand = "SELECT * FROM Jobs WHERE Username='" + UsernameTextbox.Text + "'";
OleDbConnection loginConnection = new OleDbConnection();
loginConnection.ConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Inetpub\wwwroot\JobNet\Database\jobs.mdb;Persist Security Info=False";
OleDbCommand loginCommand = new OleDbCommand(readCommand,loginConnection);
loginConnection.Open();
OleDbDataReader loginR = loginCommand.ExecuteReader();
while (loginR.Read())
{
UserN = loginR["Username"].ToString();
PassW = loginR["Password"].ToString();
if ((UsernameTextbox.Text == UserN) && (PasswordTextBox.Text == PassW))
{
Label3.Text = "Success!";
}
}
loginConnection.Close();
}
catch (OleDbException exc)
{
Label3.Text = "Error : " + exc.Message;
}
}
WHAT AM I MISSING???
I'm using VS.Net 2003 and .Net Framework version 1.1
-
- Moderator Emeritus
- Posts: 6866
- Joined: 12 Dec 2003, 02:00
- Location: JHB
- Contact:
No but that entire line is in quotes. I wrote a windows app that connects to the same database and it works.Y0da wrote:You're missing quotes after Source=Source=C:\Inetpub\wwwroot\JobNet\Database\jobs.mdb;Persist Security Info=False";
It should be
Source="C:\Inetpub\wwwroot\JobNet\Database\jobs.mdb;Persist Security Info=False";
You can't have quotes in quotes. Then is asks for an additional ";". I'm completely confused!loginConnection.ConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Inetpub\wwwroot\JobNet\Database\jobs.mdb;Persist Security Info=False";
Mechano : When you debug, does the connection open ?
Your ASPNET account also might not have appropriate permission to access the file system / directory (you have to do so explicitly)
if so, then your problem is in the CommandText of your command, with relation to the actual schema of you database.
does the jobs table have these fields your trying to read out ?
try this rather :
"SELECT UserName, Password FROM Jobs WHERE Username='" + UsernameTextbox.Text + "'"
Your ASPNET account also might not have appropriate permission to access the file system / directory (you have to do so explicitly)
if so, then your problem is in the CommandText of your command, with relation to the actual schema of you database.
does the jobs table have these fields your trying to read out ?
try this rather :
"SELECT UserName, Password FROM Jobs WHERE Username='" + UsernameTextbox.Text + "'"