C #登录代码

try
{
string NameStr=this.txtName.Text;
string AgeStr =this.txtAge.Text;
SqlConnection conn
= new SqlConnection("Data Source=hetao;Initial Catalog=TestDB;Integrated Security=True");
conn.Open();
SqlCommand cmd
=new SqlCommand("select count(*) as flag from T_UserName where name="+"'"+NameStr+"'"+"and age ="+"'"+ AgeStr+"'",conn);
cmd.ExecuteNonQuery();
int flag=Convert.ToInt32(cmd.ExecuteScalar().ToString());

if(flag>0)
{
frmMain fm
= new frmMain();
fm.Show();
this.Hide();
}
else
{
this.labelX3.Enabled=true;
this.labelX3.Text="出错";
this.labelX3.Visible=true;
}



}
catch
{
MessageBox.Show(
"用户名和密码错误");
}
原文地址:https://www.cnblogs.com/beeone/p/1989627.html