📄 tianjiakecheng.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 Default3 : System.Web.UI.Page
{
SqlConnection cn;
SqlCommand com;
protected void Page_Load(object sender, EventArgs e)
{
if ((bool)Session["IsLogined"] == false) {
Response.Redirect("index.aspx");
}
TextBox t1 = new TextBox();
TextBox t2 = new TextBox();
t1.Width = 300;
t2.Width = 300;
Button b1 = new Button();
b1.Text = "添加课程";
b1.Click += new System.EventHandler(this.button_click);
Table1.Rows[1].Cells[1].Controls.Add(t1);
Table1.Rows[2].Cells[1].Controls.Add(t2);
Table1.Rows[3].Cells[1].Text = DateTime.Now.ToShortDateString();
Table1.Rows[4].Cells[0].Controls.Add(b1);
}
public void button_click(object sender,EventArgs e) {
getconn();
string s1=((TextBox )Table1.Rows[1].Cells[1].Controls[0]).Text.ToString();
string s2=((TextBox )Table1.Rows[2].Cells[1].Controls[0]).Text.ToString();
com.CommandText = "insert into kecheng(courseid,coursename,joindate) values('" + s1 + "','" + s2 + "','" + Table1.Rows[3].Cells[1].Text + "')";
try
{
com.Connection = cn;
com.ExecuteNonQuery();
Response.Write("<script language=javascript>window.alert('添加成功')</script>");
Response.Redirect("tianjia.aspx");
}
catch (SqlException ee)
{
Response.Write(ee.Message.ToString());
}
finally { cn.Close(); }
}
public void getconn(){
string conn = ConfigurationManager.AppSettings["strconn"];
cn = new SqlConnection(conn);
cn.Open();
com = new SqlCommand();
com.Connection = cn;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -