private void btnLogin_click (object sender, EventArgs e)
{
if (txtUserName.Text.Trim()“”|| txtUserPassword.Tex.Trim()””)
}
MessageBox. Show("用户名或密码不能为空!”);
txtUserName. Focus();
return;
}
string connstring = @"Data Source=.\sqlexpress; Initial
Catalog-AddressList: Integrated Security=True”;
string sqlstr= string. Format("select from{User} where UserName=’{0}’
and Password(1)’”, txtUserName. Text. Trim(), txtUserPassword.Text.Trim();
using(SqlConnection conn=new Sqlconnection(connstring))
{
SqICommand cmd=new SqlCommand(sqlstr, conn);
conn open();
sqlDataReader sdr= cmd.ExecuteReader();
if(sdr.Read())
}
MessageBox.Show(“登录成功!“);
}
Else
{
MessageBox,Show(“用户名或密码错误,请重新输入!”,“错误”);
txtuserPassword.Text=””;
txtUserName. Focus();
}
sdr Close();
}
}
private void btnLogin_click(object sender, EventArgs e)
{
if( txtUserName.Text.Trim()|| txtUserpassword.ext.Trim()””}
MessageBox,show(“用户名或密码不能为空!”);
txtUserName. Focus()
return;
}
string connstring=DBHelperconnstring;
string sqlstr string Format("select from [ User I where UserName=”{0}”
using ( Sqlconnection conn= new sqlconnection(connstring//tim())
and Password=’(1)’”, txtuserName. Text. Trim(), txtUserPassword.Text.Trim();
{
sqlcommand cmd= new SqlCommand(sqlStr, conn);
conn Open();
SqlDataReader sdr= cmd.ExecuteReader();
if (sdr Read())
{
// MessageBox,Show("登录成功!“);
UserHelper. UserName=txtUserName.Text. Trim();
UserHelper password=txtUserPassword.Text.Trim();
this.Hide();
FormMain f new FormMain();
f.Show();
}
else
{
MessageBox.Show(“用户名或密码错误,请重新输入!”,“错误”);
txtUserName. Text=””;
txtUserpassword. Text=””;
txtUserName. Focus();
}
sdr Close();
}
}
学习心得和遇到的问题:这节课学会了vs2008的登陆界面的设计,过程很曲折,遇到了许多的问题,比如一开始没有选对数据库,导致程序无法运行,以及最最重要的数据类型的转换,里面涉及的内容很多很复杂,有的再网上也收索不到,需要自己问同学和慢慢摸索。
第三周登陆界面
最新推荐文章于 2021-06-10 08:00:00 发布