ASP访问SQL进行注册与登录(登录成功后显示其照片)

 

ASP注册代码:注册代码用是的传统的字符串相连接的方法来进行插入数据的,这个是人们普遍认为是比较不安全,如果用参数传递的方法来插入数据的话,那是相对比较安全的,它可以防止注入;

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
using System.Data.SqlClient;

 

public partial class zc : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        for (int i = 0; i <= 100; i++)
        {
            this.age.Items.Add(new ListItem(i.ToString(), i.ToString()));
        }
    }

    protected void denglu(object sender, EventArgs e)
    {
        this.Response.Redirect("dl.aspx");
   
    }

    protected void insert(object sender, EventArgs e)
    {
        string sex = "";
        StringBuilder sb = new StringBuilder();
        sb.Append(this.name.Value);
        if (Radio1.Checked)
        {
            sex = "男";
        }
        else
        {
            sex = "女";
        }
        string filename = this.File1.PostedFile.FileName;
        try
        {
        filename = DateTime.Now.Ticks.ToString() + filename.Substring(filename.LastIndexOf("."));
        this.File1.PostedFile.SaveAs(Server.MapPath("upload") + "\\" + filename);
        }
        catch (Exception)
        {
           
           
        }
      

        //sb.Append("头像:");
        //sb.Append("<img src=\"upload/" + filename + "\" />");
        //div1.InnerHtml = sb.ToString();
        bool bname = false;
         if (this.name.Value!="")
        {
            bname = true;

        }
        bool bpass=false;
        if(Password.Value.Trim()==Passwordagain.Value.Trim()&&Password.Value!="")
        {
             bpass=true;
        }
        if (bname && bpass)
        {
            try
            {
                SqlConnection con = new SqlConnection();
                con.ConnectionString = "server=.; Integrated Security=true; Initial Catalog=90";
                SqlCommand cmd = new SqlCommand("insert zc values('" + name.Value + "','" + Password.Value + "','" + sex + "','" + adress.Value + "','" + tell.Value + "','" + filename + "')", con);
                con.Open();
                cmd.ExecuteNonQuery();
                Response.Write("注册成功!");
                Label4.Text = "注册成功";
                con.Close();

            }
            catch (Exception)
            {

                Response.Write("not database!!");
            }

        }
        else
        {
            Response.Write("您的操作有误!");
        }


       
    }
}

 

 

 

 

ASP连接SQL登录代码: 

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.Text;

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

    }

    protected void start(object sender, EventArgs e)
    {
        string str="select * from zc where 姓名='"+this.name.Value.Trim()+"'";
        SqlConnection con = new SqlConnection();
        con.ConnectionString = "server=.; Integrated Security=true; Initial Catalog=90";
        SqlCommand cmd = new SqlCommand(str, con);
        SqlDataReader myreader;
        con.Open();
        myreader = cmd.ExecuteReader();
        bool a =false ;

        while (myreader.Read())
        {
            if (myreader["姓名"].ToString().Trim() == this.name.Value.Trim() && myreader["密码"].ToString().Trim() == this.Password1.Value.Trim())
            {
            
                string photo=myreader["头像"].ToString();
                this.Response.Redirect("ok.aspx?path="+photo);
               a=true;

            }
        }
        if (!a)
        {
            Response.Write("用户名不存在");
        }


        con.Close();
   
   
   
    }
}

这是登录成功后要显示的页面,成功后,它从数据库里调出想应用户的照片,在本页面显示;

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;

public partial class ok : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
     string path=this.Request.QueryString["path"];
    // Response.Write(path);
     StringBuilder sb = new StringBuilder();
      sb.Append("<img width='200 height='200' src=\"upload/" +path + "\" /");
     div1.InnerHtml = sb.ToString();
    }
}

 

 

 

我觉得,毎当在学习一门新的语言的同时,我们不要把它想的太难,我们要看到它的乐趣所在,如果你学的语言比较多的话,你就知道,其实语言都是想通的,你学会了几种,就可以做到一通百通了,一开始我学习C51单片机的时候我也是出于好奇和兴趣,我也是什么也不知道,不过我是学软件开发,我学语言的时候就十分的快,因为这可以说,C51语言就是C语言,所以我只是翻翻书就会了。我过了一个月后,我买了一块板子,我开始,先仔细看说明书里面的详细电路图。

先从网上下载了一下简单的程序,改一下I/O 口成功了我的第一个程序,以后,我先仿后写到现单机的操作基本没什么问题的了。所以说要想学好一门语言要先要好奇心,再有兴趣,这是十分必要的。

所以如果你觉的学习计算机语言不好学学的话,你可以自己写一些好玩的东西,比如写一个小的游戏,当你写完一个程序的时候,就会小有成就。慢慢的兴趣就有了

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值