📄 addnews.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.SqlClient;
public partial class addnews : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Session["user"] = "Admin";
}
protected void Button1_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection("data source=localhost;uid=sa;pwd=;database=Ebusiness");
con.Open();
SqlCommand comm = new SqlCommand();
comm.CommandText = "insert into petnews1(title,content,Auth,[date]) values(@title,@content,@Auth,@date)";
comm.Connection = con;
comm.Parameters.Add("@title", SqlDbType.Char, 100).Value = TextBox1.Text;
comm.Parameters.Add("@content", SqlDbType.VarChar, 8000).Value = TextBox2.Text;
comm.Parameters.Add("@Auth", SqlDbType.Char, 100).Value = Session["user"].ToString();
comm.Parameters.Add("@date", SqlDbType.DateTime).Value = DateTime.Now.ToString();
comm.ExecuteNonQuery();
con.Close();
ShowMassage("提交成功");
TextBox1.Text = "";
TextBox2.Text = "";
}
protected void Button2_Click(object sender, EventArgs e)
{
TextBox1.Text = "";
TextBox2.Text = "";
}
private void ShowMassage(string msg)
{
Response.Write("<script>window.alert('" + msg + "')</script>");
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -