📄 inputcustom.aspx.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.OleDb;
public partial class include_Inputcustom : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
try
{
if (Session["Leaveword"].ToString() != "pass")
{
Response.Redirect("../Default.aspx");
}
}
catch
{
Response.Redirect("../Default.aspx");
}
}
protected void Button2_Click(object sender, EventArgs e)
{
Response.Write("<Script>window.close()</Script>");
}
protected void Button1_Click(object sender, EventArgs e)
{
string name = txtName.Text.ToString().Trim();
string phone = txtPhone.Text.ToString().Trim();
string danwei = txtDanwei.Text.ToString().Trim();
string beizhu = txtBeizhu.Text.ToString().Trim();
if (name.Length < 1)
{
return;
}
Saveinfo(name, phone, danwei, beizhu);
Response.Write("<Script>alert('添加成功!')</Script>");
Clearstr();
}
//清空
private void Clearstr()
{
txtBeizhu.Text = "";
txtDanwei.Text = "";
txtName.Text = "";
txtPhone.Text = "";
}
//保存客户信息到数据库
private void Saveinfo(string sName, string sPhone, string sDanwei, string sBeizhu)
{
string myConnectionString = ConfigurationManager.ConnectionStrings["OLEDBCONNECTIONSTRING1"].ConnectionString + Server.MapPath("~") + ConfigurationManager.ConnectionStrings["OLEDBCONNECTIONSTRING2"].ConnectionString;
OleDbConnection myConnection = new OleDbConnection(myConnectionString);
string cmdText = "INSERT INTO Custom(Xingming,Dianhua,Danwei,Beizhu,Createdate)VALUES('" +
sName + "','" +
sPhone + "','" +
sDanwei + "','" +
sBeizhu + "'," +
"now())";
OleDbCommand myCommand = new OleDbCommand(cmdText, myConnection);
try
{
myConnection.Open();
myCommand.ExecuteNonQuery();
}
catch (OleDbException ex)
{
throw new Exception(ex.Message, ex);
}
finally
{
myConnection.Close();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -