导航

C #登录代码

Posted on 2011-03-20 19:08  beeone  阅读(1144)  评论(0编辑  收藏  举报
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(
"用户名和密码错误");
}