addclient.ascx.cs

来自「用vs2005和sql2000实现的小型超市管理系统」· CS 代码 · 共 71 行

CS
71
字号
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;

public partial class control_addclient : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            this.bindtogridview();
        }
            
     
      //if (Convert.ToString(Session["username"]) == "")
        //{
        //    Response.Write("<script language=javascript>alert('请登录');location='../login.aspx'</script>");
        //    return;
        //}
    }
    protected void btnaddclient_Click(object sender, EventArgs e)
    {
        
            string txtclientnum = this.txtclientnun.Text.ToString();
            string txtclientname = this.txtclientname.Text.ToString();
            string txtconpeople = this.txtconpeople.Text.ToString();
            string txtphoto= this.txtphoto.Text.ToString();
            string txtaddress = this.txtaddress.Text.ToString();
            SqlConnection strcon = DB.createConnection();
           //new SqlConnection(System.Configuration.ConfigurationManager.AppSettings["strcon"]);
            strcon.Open();
            SqlCommand scd = new SqlCommand("insert into client(客户编号,客户名称,联系人,联系电话,联系地址)values('" + txtclientnum + "','" + txtclientname + "','" + txtconpeople + "','" + txtphoto + "','" + txtaddress + "')", strcon);
            scd.ExecuteNonQuery();
            strcon.Close();
            Response.Write("<script language=javascript>alert('您已经添加成功');location='addclient.aspx'</script>");
    

    }
  
    protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
    {

    }
    private void bindtogridview()
    {
        SqlConnection con = DB.createConnection();
        SqlDataAdapter sda = new SqlDataAdapter();
        sda.SelectCommand = new SqlCommand("select * from client", con);
        DataSet ds = new DataSet();
        sda.Fill(ds, "client");
        this.GridView1.DataKeyNames = new string[] {"客户编号"};
        this.GridView1.DataSource = ds.Tables["client"];
        this.GridView1.DataBind();
    }
    protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        this.GridView1.PageIndex = e.NewPageIndex;
        this.bindtogridview();
    }

   
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?