How to map a table value to a textbox using C #
This is the code to select the user's password, where id = 1; I want to map this value to a textbox. If the value is a match, the second window form will be opened. But it doesn't work ...
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 + "");
}
0
a source to share
2 answers
Wrap your objects with operators ... so that they will be closed and disposed of when finished. Return the string you are looking for ... if GetPassword () == null, otherwise its string will not be found.
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;
}
}
}
}
0
a source to share