日期:2014-05-17  浏览次数:20823 次

ASP.NET实现注册功能的实现
本人新手,刚刚接触.NET。最近在实现注册功能时,无法写入数据库。求大神指点一下。
代码如下:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;//数据库操作需引入的命名空间
using System.Security.Cryptography;//MD5加密需引入的命名空间
using System.Data;
using System.Data.OleDb;

public partial class zhuce_xs : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected bool check(string text)               //判断实现
    {
        if (text.Contains("<") || text.Contains(">") || text.Contains("//") || text.Contains("\\")
            || text.Contains("'"))                   //检查字串
        {
            return true;
        }
        else
        {
            return false;
        }
    }
    protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
    {
        if (check(email.Text) || check(xingming.Text) || check(RadioButtonList1.Text) ||
            check(age.Text) || check(zhuanye.Text) || check(DropDownList1.Text) || check(shoujihaoma.Text) ||
            check(spassword.Text) || check(spwdagain.Text) || check(yzm.Text))  //检查字串
        {
            Response.Write("<script>alert('用户信息中不能包含特殊字符,如:<,>,',//,\\等,请审核')</script>");
        }
        else if (Session["CheckCode"].ToString().Equals(yzm.Text.ToString()))
        {
            try
                {
                    //连接并打开数据库
                    SqlConnection con = new SqlConnection("server=.;uid=sa;database=JYSystem;pwd=sa");//连接数据库,sever服务器地址,"."代表本机,uid数据库用户名,database数据库名,pwd为sa用户的密码。
                    con.Open();//打开连接
                    string strsql = "insert into St