资源预览内容
第1页 / 共6页
第2页 / 共6页
第3页 / 共6页
第4页 / 共6页
第5页 / 共6页
第6页 / 共6页
亲,该文档总共6页全部预览完了,如果喜欢就下载吧!
资源描述
注册:方法1: protected void Login(object sender, EventArgs e) /1.建立数据库连接w SqlConnection con = new SqlConnection(); con.ConnectionString = server=LENOVO-PCSQLEXPRESS; Integrated Security=true; Initial Catalog=business; /server=.;中的“.”为本机服务器名 SqlCommand cmd = new SqlCommand(select * from RegiserLogin where UserName=+this.Text1.Value+, con); SqlDataReader myreader; con.Open(); myreader = cmd.ExecuteReader(); while (myreader.Read() if (myreaderPassword.ToString().Trim() = Password1.Value) Response.Write(登录成功!); StringBuilder sb = new StringBuilder(); sb.Append(用户名:); sb.Append(myreaderUserName.ToString(); sb.Append(); sb.Append(密码:); sb.Append(myreaderPassword.ToString(); sb.Append(); sb.Append(性别:); sb.Append(myreaderSex.ToString(); sb.Append(); this.divResult.InnerHtml = sb.ToString(); break; else Response.Write(账号/密码错误,请重新输入!); break; con.Close(); 方法2:protected void Button1_Click(object sender, EventArgs e) string strCnn = server=.;database=students;integrated security=true; /string strCnn = server=.;database=students;uid=sa;pwd=123; /SqlConnection sqlCnn = new SqlConnection(); /sqlCnn.ConnectionString = strCnn; /SqlCommand sqlCmm = new SqlCommand(); /sqlCmm.CommandText = select * from student; /sqlCmm.Connection = sqlCnn; /SqlDataAdapter sqlDA = new SqlDataAdapter(sqlCmm); SqlDataAdapter sqlDA = new SqlDataAdapter(select * from student, strCnn); /它的构造函数会自动创建SqlCommad DataSet ds = new DataSet(); /sqlCnn.Open(); sqlDA.Fill(ds); /sqlCnn.Close(); this.GridView1.DataSource = ds; this.GridView1.DataBind();方法3:protected void Button2_Click(object sender, EventArgs e) string strCnn = server=.;database=students;integrated security=true; SqlConnection sqlCnn = new SqlConnection(); sqlCnn.ConnectionString = strCnn; SqlCommand sqlCmm = new SqlCommand(); /sqlCmm.CommandText = select * from student where sname= + / this.TextBox1.Text + and scity= + this.TextBox2.Text + ; sqlCmm.CommandText = string.Format(select * from student where sname=0 and scity=1,this.TextBox1.Text,this.TextBox2.Text); sqlCmm.Connection = sqlCnn; sqlCnn.Open(); SqlDataReader reader = sqlCmm.ExecuteReader(); /ExecuteScalor if (reader.Read() this.Response.Write(OK); else this.Response.Write(Error); /if (reader.HasRows) / / this.Response.Write(ok); / /else / / this.Response.Write(Error!); / reader.Close(); sqlCnn.Close(); 方法4:登录:方法1:String username = txtName.Text; /将用户名输入框的内容赋值给变量 string password = MD5ToString(txtPassword2.Text); /将密码输入框的内容赋值给变量 string email = txtEmail.Text; /将邮件输入框的内容复制给变量 string birthday = txtBirthday.Text; /将生日输入框的内容复制给变量 /1.建立数据库连接 SqlConnection con = new SqlConnection(); con.ConnectionString = server=LENOVO-PCSQLEXPRESS; Integrated Security=true; Initial Catalog=business; con.Open(); /打开数据库 SqlCommand cmd = con.CreateCommand(); /创建一个数据库命令行 cmd.CommandText = insert into Tongxuelu(UserName,UserPassword,UserEmail,UserBirthday) values(un,pw,ue,ub); /数据库命令的内容(un,pw是点位符,将会在下面的语句中赋值) cmd.Parameters.AddWithValue(un, username); / 将username 赋值给命令行的 un” cmd.Parameters.AddWithValue(pw, password); / 将Password 赋值给命令行的 pw” cmd.Parameters.AddWithValue(ue, email); / 将email 赋值给命令行的 ue” cmd.Parameters.AddWithValue(ub, birthday); / 将birthday 赋值给命令行的 ub” cmd.ExecuteNonQuery(); / 执行数据库命令 接收受影响行数
网站客服QQ:2055934822
金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号