⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 addclient.ascx.cs

📁 用vs2005和sql2000实现的小型超市管理系统
💻 CS
字号:
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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -