PDS8475
Active member
- Joined
- Jun 25, 2019
- Messages
- 41
- Programming Experience
- Beginner
Hi I have been messing around with this for two day trying to get it to work.
At the moment I am getting the following rather long Exception message
I ended up using a string builder program to generate the connection string and the select statement. Not that they are exactly right as I want them to say the database is in the same folder as this program, But getting the code just to work is the main issue.
My code is as follows
If I put reader.read() a while statement as in
I get the following Exception message
I realise the part of the select statement that gets input from Textbox2 (WHERE( Admins.Name LIKE 'UN')) may be wrong so I tried changing UN for a fixed value and get a PW out of range exception.
Since I don't fully understand these exception messages I feel I am going round in circles.
Any help would be much appreciated
At the moment I am getting the following rather long Exception message
I ended up using a string builder program to generate the connection string and the select statement. Not that they are exactly right as I want them to say the database is in the same folder as this program, But getting the code just to work is the main issue.
My code is as follows
C#:
private void Pass_textBox_TextChanged(object sender, EventArgs e)
{
string UN = TextBox2.Text;
string pass = Pass_textBox.Text;
string connString = @"Provider = Microsoft.Jet.OLEDB.4.0; Data Source = C:\Users\Paul\source\repos\FixIT\FixIT\bin\Debug\FixITAdmin.mdb";
List<String> passw = new List<String>();
OleDbConnection oleConn = new OleDbConnection(connString);
try
{
oleConn.Open();
string my_querry = "SELECT Admins.PW AS [Admins PW] FROM Admins AS Admins WHERE( Admins.Name LIKE 'UN') ORDER BY Admins.Name";
OleDbCommand cmd = new OleDbCommand(my_querry , oleConn);
OleDbDataReader reader = cmd.ExecuteReader();
reader.Read();
passw.Add(reader["PW"].ToString());
string result = cmd.ExecuteScalar().ToString();
MessageBox.Show(result);
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
finally
{
oleConn.Close();
}
if (Pass_textBox.Text == "")
{
Pass_textBox.PasswordChar = '\0';
Pass_textBox.Text = "Password";
}
}
If I put reader.read() a while statement as in
C#:
while (reader.Read())
{
passw.Add(reader["PW"].ToString());
}
I get the following Exception message
I realise the part of the select statement that gets input from Textbox2 (WHERE( Admins.Name LIKE 'UN')) may be wrong so I tried changing UN for a fixed value and get a PW out of range exception.
Since I don't fully understand these exception messages I feel I am going round in circles.
Any help would be much appreciated