here is the code
I am getting this error: "data type mismatch in criteria expression" Can you tell me why?
here's the code
try
{
string constring = @"Provider = Microsoft.ACE.OLEDB.12.0; Data source= bla.accdb;Persist Security Info=True;";
OleDbConnection conexiune = new OleDbConnection(constring);
OleDbCommand cmdDataBase = new OleDbCommand("Select * from Table1 where username =' " + this.textBox1.Text+"' and pass ='"+this.textBox2.Text+"';", conexiune);
OleDbDataReader myReader;
conexiune.Open();
myReader = cmdDataBase.ExecuteReader();
int count = 0;
while (myReader.Read())
{ count = count + 1; }
if (count == 1)
{
MessageBox.Show("FS");
}
else
{
MessageBox.Show("no");
}
}
catch (Exception ex)
{ MessageBox.Show(ex.Message); }
}

VulpesRank #55 · 29.2K reputationPosted Mar 11, 2014, 11:01 AM EDT
Also, it's difficult to see how the username and password columns can be anything other than strings in the database which is the usual reason for this error.
Munesh SharmaRank #174 · 13.9K reputationPosted Mar 11, 2014, 11:06 PM EDT
{
try
{
string str = "server = MUNESH\\SQL2008R2;Database=datastore;UID=sa;Password=123;";
SqlConnection con = new SqlConnection(str);
SqlCommand cmd = new SqlCommand("Select * from login where username = '" + this.textBox1.Text + "' and password = '" + this.textBox2.Text + "'", con);
SqlDataReader myreader;
con.Open();
myreader = cmd.ExecuteReader();
int count = 0;
while (myreader.Read())
{
count = count + 1;
}
if (count == 1)
{
MessageBox.Show("Username and password correct");
}
else if (count > 1)
{
MessageBox.Show("Duplicate username and password");
}
else
MessageBox.Show(" username and password incorrect");
con.Close();
}
catch (Exception es)
{
MessageBox.Show(es.Message);
}
}