EDN Admin
Well-known member
I am getting an "Error opening database connection: Incorrect syntax near the keyword user." with the following code:
<pre class="prettyprint OleDbConnection dbConn = new OleDbConnection(strConnectionString);
string queryString = "SELECT userLogin, userPassword FROM user WHERE userLogin=" + this.txtUserID.Text + " AND userPassword=" + this.pswPassword.Password + ";";
MessageBox.Show(queryString);
OleDbCommand command = new OleDbCommand(queryString, dbConn);
dbConn.Open();
OleDbDataReader reader = command.ExecuteReader();
// Read before accessing data.
reader.Read();
if (reader.HasRows)
{
// userID plus user password combination found
MessageBox.Show("user plus password combination found");
}
else
{
// userID plus user password combination not found
MessageBox.Show("user plus password combination not found");
}
// call Close when done reading.
reader.Close();
// Close this OleDbConnection instance
dbConn.Close();[/code]
The error happens at the command.ExecuteReader(); line.
The queryString looks like this: "SELECT userLogin, userPassword FROM user WHERE userLogin=jdoe AND userPassword=asdfasdf;"
All I want to do is input a user ID and password in my modal dialog box and then validate it against my user table in the database. <hr class="sig REvans
View the full article
<pre class="prettyprint OleDbConnection dbConn = new OleDbConnection(strConnectionString);
string queryString = "SELECT userLogin, userPassword FROM user WHERE userLogin=" + this.txtUserID.Text + " AND userPassword=" + this.pswPassword.Password + ";";
MessageBox.Show(queryString);
OleDbCommand command = new OleDbCommand(queryString, dbConn);
dbConn.Open();
OleDbDataReader reader = command.ExecuteReader();
// Read before accessing data.
reader.Read();
if (reader.HasRows)
{
// userID plus user password combination found
MessageBox.Show("user plus password combination found");
}
else
{
// userID plus user password combination not found
MessageBox.Show("user plus password combination not found");
}
// call Close when done reading.
reader.Close();
// Close this OleDbConnection instance
dbConn.Close();[/code]
The error happens at the command.ExecuteReader(); line.
The queryString looks like this: "SELECT userLogin, userPassword FROM user WHERE userLogin=jdoe AND userPassword=asdfasdf;"
All I want to do is input a user ID and password in my modal dialog box and then validate it against my user table in the database. <hr class="sig REvans
View the full article