初学者求简单的实现登录的代码
时间:2011-12-07
来源:互联网
应用C#+SQLServer,小弟初学者,各位大侠帮帮忙啊
作者: ten517 发布时间: 2011-12-07
挺简单的,自己动手试一下印象才深刻啊。
作者: mizuho_2006 发布时间: 2011-12-07
假设有个按钮,我现在写按钮的单机事件
private Login_Click(Object sender ,EventArgs e)
{
SqlConnection con=new SqlConnection("Sever=.,database=Test,UID=sa,PWD=as");
SqlCommand cmd=new SqlCommand(String.contact("select count(Username) from UserTable where User='",Txt_Name.Text.Trim(),", Password='",Txt_Password.Text.Trim(),"'"));
Cmd.Connection=con;
con.open();
Int result=Cmd.ExecuteScalar();
con.close();
com.close();
if(result==1)
{
Mainform main=Mainform();//登录成功。
main.show();
this.Hide();
}
else
{
Message.Show("用户名密码错误!")
}
}
private Login_Click(Object sender ,EventArgs e)
{
SqlConnection con=new SqlConnection("Sever=.,database=Test,UID=sa,PWD=as");
SqlCommand cmd=new SqlCommand(String.contact("select count(Username) from UserTable where User='",Txt_Name.Text.Trim(),", Password='",Txt_Password.Text.Trim(),"'"));
Cmd.Connection=con;
con.open();
Int result=Cmd.ExecuteScalar();
con.close();
com.close();
if(result==1)
{
Mainform main=Mainform();//登录成功。
main.show();
this.Hide();
}
else
{
Message.Show("用户名密码错误!")
}
}
作者: Tsapi 发布时间: 2011-12-07
多多练习,慢慢就会了...
作者: wangheng0411 发布时间: 2011-12-07
相关阅读 更多
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28