tags:

views:

376

answers:

2

This is code for select user password where id = 1 ; I want to match this value to a text box. If the value is a match then second window form will be open. But it is not working ...

OleDbConnection con = new OleDbConnection(database2.conn);
con.Open();
OleDbCommand OCom = new OleDbCommand("select user_pasword from tblpasword where id = 1", con);
OleDbDataReader Dreader = OCom.ExecuteReader();

while (Dreader.Read())
{
  MessageBox.Show(Dreader + "");
}
+1  A: 

If I am not wrong I think you can use

while(Dreader.Read())
{
    if(Dreader["_password"].ToString()==txtbox.text)
    {
    objectofform.show()
    }
}
Pranali Desai
A: 

Wrap your objects in using statements....so they will close and dispose when done. Return the string you are looking for... if GetPassword() == null, not found otherwise its the string returned.

public string GetPassword()
{

using (OleDbConnection con = new OleDbConnection(database2.conn))
{

using (OleDbCommand OCom = new OleDbCommand("select user_pasword from tblpasword where id = 1", con))
{
    con.Open();

    using (IDataReader Dreader = OCom.ExecuteReader())
    {
     if (Dreader.Read())
     {
      return Dreader.GetString(0);
     } else return null;
    }
}

}

}
CRice