打印本文 打印本文 关闭窗口 关闭窗口
(ASP.NET)修改和删除DataGrid行——数据库访问
作者:武汉SEO闵涛  文章来源:敏韬网  点击数5239  更新时间:2009/4/23 10:47:11  文章录入:mintao  责任编辑:mintao
       

        /// <summary>

        /// 设计器支持所需的方法 - 不要使用代码编辑器修改

        /// 此方法的内容。

        /// </summary>

        private void InitializeComponent()

        {   

            this.LinkButton1.Click += new System.EventHandler(this.LinkButton1_Click);

            this.DataGrid1.Disposed += new System.EventHandler(this.DataGrid1_Disposed);

            this.DataGrid1.CancelCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.DataGrid1_CancelCommand);

            this.DataGrid1.EditCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.DataGrid1_EditCommand);

            this.DataGrid1.UpdateCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.DataGrid1_UpdateCommand);

            this.DataGrid1.DeleteCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.DataGrid1_DeleteCommand);

            this.DataGrid1.SelectedIndexChanged += new System.EventHandler(this.DataGrid1_SelectedIndexChanged);

            this.Load += new System.EventHandler(this.Page_Load);

 

        }

        #endregion

 

        private void LinkButton1_Click(object sender, System.EventArgs e)

        {

            AddPublisher();

        }

 

        /// <summary>

        /// 添加

        /// </summary>

        private void AddPublisher()

        {

            string sql="insert into publishers(pub_id,pub_name,city,state,country) values(@pubid,@pubname,@city,@state,@country)";

 

            SqlConnection con=new SqlConnection("server=accp-lzh;uid=sa;pwd=sasa;database=pubs");

            SqlCommand cmd=new SqlCommand(sql,con);

 

            cmd.Parameters.Add(new SqlParameter("@pubid",SqlDbType.Char,4));

            cmd.Parameters["@pubid"].Value=this.TextBox1.Text;

            cmd.Parameters.Add(new SqlParameter("@pubname",SqlDbType.VarChar ,40));

            cmd.Parameters["@pubname"].Value=this.TextBox2.Text;

            cmd.Parameters.Add(new SqlParameter("@city",SqlDbType.Char,20));

            cmd.Parameters["@city"].Value=this.TextBox3.Text;

            cmd.Parameters.Add(new SqlParameter("@state",SqlDbType.Char,2));

            cmd.Parameters["@state"].Value=this.TextBox4.Text;

            cmd.Parameters.Add(new SqlParameter("@country",SqlDbType.VarChar ,30));

            cmd.Parameters["@country"].Value=this.TextBox5.Text;

 

            cmd.Connection.Open();

            cmd.ExecuteNonQuery();

上一页  [1] [2] [3] [4] [5] [6] [7] [8]  下一页

打印本文 打印本文 关闭窗口 关闭窗口