1个回答
展开全部
创建两个类调用
(有时代码都正确但还是注册不了,可能是数据表有问题,删除重表建一张)
****************************************person类:
using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
/// <summary>
///person 的摘要说明
/// </summary>
public class person
{
public string uName;
public string uPwd;
public string uSex;
public person()
{
//
//TODO: 在此处添加构造函数逻辑
//
}
}
*********************************************personOperate类
using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
/// <summary>
///personOperate 的摘要说明
/// </summary>
public class personOperate
{
public personOperate()
{
//
//TODO: 在此处添加构造函数逻辑
//
}
public static SqlConnection createConnection()
{
SqlConnection con = new SqlConnection("server=.;database=log;uid=sa;pwd=sa");
return con;
}
public static bool insertOperate(person p)
{
try
{
SqlConnection con =personOperate.createConnection();
con.Open();
SqlCommand cmd = new SqlCommand("insert into www values(@uName,@uPwd,@uSex)", con);
SqlParameter para = new SqlParameter("@uName", SqlDbType.VarChar, 50);
para.Value = p.uName;
cmd.Parameters.Add(para);
para = new SqlParameter("@uPwd", SqlDbType.VarChar, 50);
para.Value = p.uPwd;
cmd.Parameters.Add(para);
para = new SqlParameter("@uSex", SqlDbType.VarChar, 2);
para.Value = p.uSex;
cmd.Parameters.Add(para);
cmd.ExecuteNonQuery();
return true;
}
catch (Exception e)
{
return false;
}
}
}
********************************************注册页面代码
using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btgo_Click(object sender, EventArgs e)
{
person p = new person();
p.uName = this.tbUser.Text;
p.uPwd = this.tbPwd.Text;
if (this.rbman.Checked)
{
p.uSex = "男";
}
else
{
p.uSex = "女";
}
if(personOperate.insertOperate(p))
{
Response.Write("注册成功");
}
else
{
Response.Write("失败");
}
Res
注册二代码:
protected void btnsend_Click(object sender, EventArgs e)
{
SqlConnection con = DB.createConnection();
con.Open();
string cmdtext = "insert into newreplay(mname,msubject,mcontent,mphone,madd,mqq,mmail,mhttp,mface,mip,mdatetime,mreplaytime) values(@name,@subject,@content,@phone,@add,@qq,@mail,@http,@face,@ip,@datetime,@datetime)";
SqlCommand cmd = new SqlCommand(cmdtext, con);
cmd.Parameters.Add("@name", SqlDbType.VarChar, 50);
cmd.Parameters["@name"].Value = this.tname.Text;
cmd.Parameters.Add("@subject", SqlDbType.VarChar, 50);
cmd.Parameters["@subject"].Value = this.tsubject.Text;
cmd.Parameters.Add("@content", SqlDbType.Text);
cmd.Parameters["@content"].Value = this.tcontent.Text;
cmd.Parameters.Add("@phone", SqlDbType.VarChar, 50);
cmd.Parameters["@phone"].Value = this.tphone.Text;
cmd.Parameters.Add("@add", SqlDbType.VarChar, 50);
cmd.Parameters["@add"].Value = this.tadd.Text;
cmd.Parameters.Add("@qq", SqlDbType.VarChar, 50);
cmd.Parameters["@qq"].Value = this.tqq.Text;
cmd.Parameters.Add("@mail", SqlDbType.VarChar, 50);
cmd.Parameters["@mail"].Value = this.tmail.Text;
cmd.Parameters.Add("@http", SqlDbType.VarChar, 50);
cmd.Parameters["@http"].Value = this.thttp.Text;
cmd.Parameters.Add("@face", SqlDbType.VarChar, 50);
cmd.Parameters["@face"].Value = this.dface.SelectedValue.ToString();
cmd.Parameters.Add("@ip", SqlDbType.VarChar, 50);
cmd.Parameters["@ip"].Value = GetIP();
cmd.Parameters.Add("@datetime", SqlDbType.DateTime);
cmd.Parameters["@datetime"].Value = DateTime.Now.ToString();
try
{
cmd.ExecuteNonQuery();
con.Close();
Response.Write("<script>alert('发表成功')</script>");
this.tadd.Text = "";
this.tcontent.Text = "";
this.thttp.Text = "";
this.tmail.Text = "";
this.tsubject.Text = "";
this.tphone.Text = "";
this.tname.Text = "";
this.tqq.Text = "";
}
catch (Exception error)
{
throw new System.Exception(error.Message);
}
}
登陆:
public partial class LOGIN : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
SqlConnection con = DB.createConnec();
con.Open();
SqlCommand cmd = new SqlCommand("select * from LOGIN where name='" + this.TextBox1.Text + "'and password='" + this.TextBox2.Text + "'", con);
SqlDataReader dr = cmd.ExecuteReader();
if (dr.Read())
{
Session["username"] = dr["name"]; //从数据库读出
Session["userpassword"] = dr["password"]; //从数据库读出
if ((int)Session["userpassword"] == 1) //类型要注意 还有一种是SESSION["WWW"].TOSTRING()=="1"; //!=
{
Response.Redirect("TIME.aspx");
}
else if ((int)Session["userpassword"] == 2)
{
Response.Redirect("add.aspx");
}
else
{
Response.Redirect("list.aspx");
}
}
else
{
Response.Write("ksks");
}
con.Close();
}
}
要是可以给我好评好么!我在收集分数
(有时代码都正确但还是注册不了,可能是数据表有问题,删除重表建一张)
****************************************person类:
using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
/// <summary>
///person 的摘要说明
/// </summary>
public class person
{
public string uName;
public string uPwd;
public string uSex;
public person()
{
//
//TODO: 在此处添加构造函数逻辑
//
}
}
*********************************************personOperate类
using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
/// <summary>
///personOperate 的摘要说明
/// </summary>
public class personOperate
{
public personOperate()
{
//
//TODO: 在此处添加构造函数逻辑
//
}
public static SqlConnection createConnection()
{
SqlConnection con = new SqlConnection("server=.;database=log;uid=sa;pwd=sa");
return con;
}
public static bool insertOperate(person p)
{
try
{
SqlConnection con =personOperate.createConnection();
con.Open();
SqlCommand cmd = new SqlCommand("insert into www values(@uName,@uPwd,@uSex)", con);
SqlParameter para = new SqlParameter("@uName", SqlDbType.VarChar, 50);
para.Value = p.uName;
cmd.Parameters.Add(para);
para = new SqlParameter("@uPwd", SqlDbType.VarChar, 50);
para.Value = p.uPwd;
cmd.Parameters.Add(para);
para = new SqlParameter("@uSex", SqlDbType.VarChar, 2);
para.Value = p.uSex;
cmd.Parameters.Add(para);
cmd.ExecuteNonQuery();
return true;
}
catch (Exception e)
{
return false;
}
}
}
********************************************注册页面代码
using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btgo_Click(object sender, EventArgs e)
{
person p = new person();
p.uName = this.tbUser.Text;
p.uPwd = this.tbPwd.Text;
if (this.rbman.Checked)
{
p.uSex = "男";
}
else
{
p.uSex = "女";
}
if(personOperate.insertOperate(p))
{
Response.Write("注册成功");
}
else
{
Response.Write("失败");
}
Res
注册二代码:
protected void btnsend_Click(object sender, EventArgs e)
{
SqlConnection con = DB.createConnection();
con.Open();
string cmdtext = "insert into newreplay(mname,msubject,mcontent,mphone,madd,mqq,mmail,mhttp,mface,mip,mdatetime,mreplaytime) values(@name,@subject,@content,@phone,@add,@qq,@mail,@http,@face,@ip,@datetime,@datetime)";
SqlCommand cmd = new SqlCommand(cmdtext, con);
cmd.Parameters.Add("@name", SqlDbType.VarChar, 50);
cmd.Parameters["@name"].Value = this.tname.Text;
cmd.Parameters.Add("@subject", SqlDbType.VarChar, 50);
cmd.Parameters["@subject"].Value = this.tsubject.Text;
cmd.Parameters.Add("@content", SqlDbType.Text);
cmd.Parameters["@content"].Value = this.tcontent.Text;
cmd.Parameters.Add("@phone", SqlDbType.VarChar, 50);
cmd.Parameters["@phone"].Value = this.tphone.Text;
cmd.Parameters.Add("@add", SqlDbType.VarChar, 50);
cmd.Parameters["@add"].Value = this.tadd.Text;
cmd.Parameters.Add("@qq", SqlDbType.VarChar, 50);
cmd.Parameters["@qq"].Value = this.tqq.Text;
cmd.Parameters.Add("@mail", SqlDbType.VarChar, 50);
cmd.Parameters["@mail"].Value = this.tmail.Text;
cmd.Parameters.Add("@http", SqlDbType.VarChar, 50);
cmd.Parameters["@http"].Value = this.thttp.Text;
cmd.Parameters.Add("@face", SqlDbType.VarChar, 50);
cmd.Parameters["@face"].Value = this.dface.SelectedValue.ToString();
cmd.Parameters.Add("@ip", SqlDbType.VarChar, 50);
cmd.Parameters["@ip"].Value = GetIP();
cmd.Parameters.Add("@datetime", SqlDbType.DateTime);
cmd.Parameters["@datetime"].Value = DateTime.Now.ToString();
try
{
cmd.ExecuteNonQuery();
con.Close();
Response.Write("<script>alert('发表成功')</script>");
this.tadd.Text = "";
this.tcontent.Text = "";
this.thttp.Text = "";
this.tmail.Text = "";
this.tsubject.Text = "";
this.tphone.Text = "";
this.tname.Text = "";
this.tqq.Text = "";
}
catch (Exception error)
{
throw new System.Exception(error.Message);
}
}
登陆:
public partial class LOGIN : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
SqlConnection con = DB.createConnec();
con.Open();
SqlCommand cmd = new SqlCommand("select * from LOGIN where name='" + this.TextBox1.Text + "'and password='" + this.TextBox2.Text + "'", con);
SqlDataReader dr = cmd.ExecuteReader();
if (dr.Read())
{
Session["username"] = dr["name"]; //从数据库读出
Session["userpassword"] = dr["password"]; //从数据库读出
if ((int)Session["userpassword"] == 1) //类型要注意 还有一种是SESSION["WWW"].TOSTRING()=="1"; //!=
{
Response.Redirect("TIME.aspx");
}
else if ((int)Session["userpassword"] == 2)
{
Response.Redirect("add.aspx");
}
else
{
Response.Redirect("list.aspx");
}
}
else
{
Response.Write("ksks");
}
con.Close();
}
}
要是可以给我好评好么!我在收集分数
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询