.aspx制作链接数据库并互相跳转的登录与注册
2012-10-08 13:46:41 来源:WEB开发网</table>
</div>
</form>
</body>
</html>
WebZhuCe.aspx.cs:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration;
using System.Data.SqlClient;
using System.Text;
namespace Webdenglu
{
public partial class WebZhuCe : System.Web.UI.Page
{
string sqlserverstr = ConfigurationManager.ConnectionStrings["sqlservercon"].ConnectionString;
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection(sqlserverstr);
conn.Open();
SqlCommand sqlcmd = new SqlCommand();
sqlcmd.Connection = conn;
sqlcmd.CommandText = " insert into Mebiuss(UserName,PassWord,Sex,Hobby,Email,Birthday,HeadPortrait,BriefIntroduction) values(@UserName,@PassWord,@Sex,@Hobby,@Email,@Birthday,@HeadPortrait,@BriefIntroduction)";
sqlcmd.Parameters.AddWithValue("UserName", username.Text);
sqlcmd.Parameters.AddWithValue("PassWord", Password.Text);
if (Sex1.Checked)
{
sqlcmd.Parameters.AddWithValue("@Sex", Sex1.Text);
Session["Sex"] = Sex1.Text;
}
else
{
sqlcmd.Parameters.AddWithValue("@Sex", Sex2.Text);
Session["Sex"] = Sex2.Text;
}
string str = "";
foreach (ListItem li in CheckBoxList1.Items)
{
if (li.Selected)
{
str += li.Text + "、";
}
}
sqlcmd.Parameters.AddWithValue("@Hobby", str);
Response.Write("<script>function isEmail(str){var reg=/^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(\'.'[a-zA-Z0-9_-])+/;return reg.test(str); } var str='" + Email.Text + "'; document.write(isEmail(str)+'<br />'); </script>");
sqlcmd.Parameters.AddWithValue("@Email", Email.Text);
sqlcmd.Parameters.AddWithValue("@Birthday", Birthday.Text);
StringBuilder sb = new StringBuilder();
string filename = this.file1.PostedFile.FileName;
filename = DateTime.Now.Ticks.ToString() + filename.Substring(filename.LastIndexOf("."));
this.file1.PostedFile.SaveAs(Server.MapPath("upload") + "\\" + filename);
sb.Append("<img src=\"upload/" + filename + "\" />");
sqlcmd.Parameters.AddWithValue("@HeadPortrait", sb.ToString());
sqlcmd.Parameters.AddWithValue("@BriefIntroduction", BriefIntroduction.Text);
Response.Write("<script>alert('注册成功');window.location='WebFanKui.aspx';</script>");
sqlcmd.ExecuteNonQuery();
conn.Close();
conn.Dispose();
Session["username"] = username.Text;
Session["password"] = Password.Text;
更多精彩
赞助商链接