using System.Data.SqlClient;
SqlConnection myconn = new SqlConnection("server=LAPTOP-0LGEPDGC\\SQLEXPRESS;Trusted_Connection=SSPI;database=User");
SqlCommand mycomm;
SqlDataReader mydr;
private void btnFPwd_Click(object sender, EventArgs e)
{
try
{
if (myconn.State == ConnectionState.Closed)
{
myconn.Open();
}
mycomm = new SqlCommand("select userPwd from userTable where userName = '" + txtFindName.Text.Trim() + "'", myconn);
mydr = mycomm.ExecuteReader();
if (txtFindName.Text == "")
{
MessageBox.Show("用户名不可为空!");
txtFindName.Focus();
}
else
{
if (mydr.Read())
{
labPwd.Text = mydr[0].ToString();
//labPwd.Text = Convert.ToString(mydr.GetSqlValue(0));//一般不用
}
}
myconn.Close();
mydr.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message.ToString());
}
}
private void btnFLogin_Click(object sender, EventArgs e)
{
Login login = new Login();
login.ShowDialog();
this.Hide();
}