欢迎来到天天文库
浏览记录
ID:50985736
大小:47.02 KB
页数:6页
时间:2020-03-08
《SQL注册登录连接几种形式.doc》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、注册:方法1:protectedvoidLogin(objectsender,EventArgse){//1.建立数据库连接wSqlConnectioncon=newSqlConnection();con.ConnectionString=@"server=LENOVO-PCSQLEXPRESS;IntegratedSecurity=true;InitialCatalog=business";//server=.;中的“.”为本机服务器名SqlCommandcmd=newSqlCommand("select*fromRegiserLoginw
2、hereUserName='"+this.Text1.Value+"'",con);SqlDataReadermyreader;con.Open();myreader=cmd.ExecuteReader();while(myreader.Read()){if(myreader["Password"].ToString().Trim()==Password1.Value){Response.Write("登录成功!");StringBuildersb=newStringBuilder();sb.Append("用户名:");sb.Append(m
3、yreader["UserName"].ToString());sb.Append("");sb.Append("密码:");sb.Append(myreader["Password"].ToString());sb.Append("");sb.Append("性别:");sb.Append(myreader["Sex"].ToString());sb.Append("");this.divResult.InnerHtml=sb.ToString();break;}else{Response.Write("账号/密
4、码错误,请重新输入!");}break;}con.Close();}方法2:protectedvoidButton1_Click(objectsender,EventArgse){stringstrCnn="server=.;database=students;integratedsecurity=true";//stringstrCnn="server=.;database=students;uid=sa;pwd=123";//////SqlConnectionsqlCnn=newSqlConnection();//////sqlCnn.Co
5、nnectionString=strCnn;//////SqlCommandsqlCmm=newSqlCommand();//////sqlCmm.CommandText="select*fromstudent";//////sqlCmm.Connection=sqlCnn;//////SqlDataAdaptersqlDA=newSqlDataAdapter(sqlCmm);SqlDataAdaptersqlDA=newSqlDataAdapter("select*fromstudent",strCnn);//它的构造函数会自动创建SqlCo
6、mmadDataSetds=newDataSet();//sqlCnn.Open();sqlDA.Fill(ds);//sqlCnn.Close();this.GridView1.DataSource=ds;this.GridView1.DataBind();}方法3:protectedvoidButton2_Click(objectsender,EventArgse){stringstrCnn="server=.;database=students;integratedsecurity=true";SqlConnectionsqlCnn=ne
7、wSqlConnection();sqlCnn.ConnectionString=strCnn;SqlCommandsqlCmm=newSqlCommand();//sqlCmm.CommandText="select*fromstudentwheresname='"+//this.TextBox1.Text+"'andscity='"+this.TextBox2.Text+"'";sqlCmm.CommandText=string.Format("select*fromstudentwheresname='{0}'andscity='{1}'
8、",this.TextBox1.Text,this.TextBox2.Text);sqlCmm.Connection=sqlCnn;sqlCnn.Op
此文档下载收益归作者所有