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

📄 stmanageraddproduct.aspx.cs

📁 数据库:Microsoft SQL Server 2000。 技术平台:Microsoft .NET Framework 2.0.0.0版本。 IIS:Internet Informati
💻 CS
字号:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using System.Configuration;

namespace STcontract.Manager
{
	/// <summary>
	/// ManagerStat 的摘要说明。
	/// </summary>
	public class ManagerStat : System.Web.UI.Page
	{
		protected System.Web.UI.WebControls.Button STDe_add;
		protected System.Web.UI.WebControls.Button STDe_reset;
		protected System.Web.UI.WebControls.TextBox STProdName;
		protected System.Web.UI.WebControls.Label STProd_warn;
		SqlConnection STconn;
	
		private void Page_Load(object sender, System.EventArgs e)
		{
			if(Session["STNickName"] != null)
			{
				//获得数据库连接字符串
				string STconnection = ConfigurationSettings.AppSettings["strconnection"];
				//创建数据库连接
				STconn = new SqlConnection(STconnection);
			}
			else
			{
				Response.Redirect("../Index.aspx");
			}

		}

		#region Web 窗体设计器生成的代码
		override protected void OnInit(EventArgs e)
		{
			//
			// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
			//
			InitializeComponent();
			base.OnInit(e);
		}
		
		/// <summary>
		/// 设计器支持所需的方法 - 不要使用代码编辑器修改
		/// 此方法的内容。
		/// </summary>
		private void InitializeComponent()
		{    
			this.STDe_add.Click += new System.EventHandler(this.STDe_add_Click);
			this.Load += new System.EventHandler(this.Page_Load);

		}
		#endregion

		private void STDe_add_Click(object sender, System.EventArgs e)
		{
			//创建插入产品信息的sql语句
			string STstrsql = "insert into STProd(STProdName) values(@STProdName)";
			//根据sql语句,创建SqlCommand对象
			SqlCommand STcmd = new SqlCommand(STstrsql,STconn);
			STcmd.Parameters.Add(new SqlParameter("@STProdName",SqlDbType.VarChar,50));
			STcmd.Parameters["@STProdName"].Value = STProdName.Text ;
			STcmd.Connection.Open();
			try
			{
				//执行sql语句
				STcmd.ExecuteNonQuery();
				//Label提示添加成功
				STProd_warn.Text = "添加成功!";
				//提示信息的字体颜色
				STProd_warn.Style["color"] = "red";
				Response.Redirect("STManagerProduct.aspx");
			}
			catch(SqlException)
			{
				//Label提示添加失败
				STProd_warn.Text = "添加失败!";
				STProd_warn.Style["color"] = "red";
				Response.Redirect("STManagerAddProduct.aspx");
			}
		}
	}
}

⌨️ 快捷键说明

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