?? admincourse.aspx.cs
字號(hào):
?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 adminCourse : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
ddlBind();
CourceDetailsShow();
}
}
private void ddlBind()
{
string connStr = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString; //取出連接字符串
string SqlStr = "SELECT teaID,teaName from Teacher";
DataSet ds = new DataSet();
SqlConnection conn = new SqlConnection(connStr); //創(chuàng)建連接對(duì)象
if (conn.State.ToString() == "Closed") //如果連接關(guān)閉,打開
conn.Open();
SqlDataAdapter da = new SqlDataAdapter(SqlStr, conn);
da.Fill(ds); //從數(shù)據(jù)庫中取數(shù)據(jù)放到DataSet數(shù)據(jù)集中
if (conn.State.ToString() == "Open")
conn.Close();
ddlTeacherName.DataSource = ds.Tables[0].DefaultView;
ddlTeacherName.DataTextField = "teaName"; //下拉列表框每項(xiàng)顯示教師姓名
ddlTeacherName.DataValueField = "teaID"; //下拉列表框每項(xiàng)的值為教師編號(hào)
ddlTeacherName.DataBind();
}
private void CourceDetailsShow()
{
string connStr = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString; //取出連接字符串
string SqlStr = "SELECT Cource.*,Teacher.teaName from Cource,Teacher where Cource.teaID=Teacher.teaID and Cource.courceID='" + Request["courceID"].ToString() + "' and Cource.teaID='" + Request["teaID"].ToString() + "'";
SqlConnection conn = new SqlConnection(connStr); //創(chuàng)建連接對(duì)象
try
{
if (conn.State.ToString() == "Closed") //連接如果關(guān)閉,打開
conn.Open();
SqlCommand cmd = new SqlCommand(SqlStr, conn);
SqlDataReader sdr = cmd.ExecuteReader();
if (sdr.Read())
{
courceName.Text = sdr["courceName"].ToString();
txtName.Text = sdr["courceName"].ToString();
ddlTeacherName.SelectedItem.Text = sdr["teaName"].ToString();
txtTime.Text = sdr["courceTime"].ToString();
txtAddress.Text = sdr["courceAddress"].ToString();
txtDetails.Text = sdr["courceInfo"].ToString();
}
else
{
Response.Write("數(shù)據(jù)庫錯(cuò)誤,沒查詢到該門課程!");
Response.End();
}
}
catch (Exception ex) //異常處理
{
Response.Write("數(shù)據(jù)庫錯(cuò)誤,錯(cuò)誤原因:" + ex.Message);
Response.End();
}
finally
{
if (conn.State.ToString() == "Open") //如果連接打開,關(guān)閉
conn.Close();
}
}
//修改課程事件
protected void imgBtnConfirm_Click(object sender, ImageClickEventArgs e)
{
string connStr = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString; //取出連接字符串
string SqlStr = "update Cource set courceName='"+txtName.Text+"',teaID='"+ddlTeacherName.SelectedValue+"',courceTime='"+txtTime.Text+"',courceAddress='"+txtAddress.Text+"',courceInfo='"+txtDetails.Text+"' where courceID='" + Request["courceID"].ToString() + "' and teaID='" + Request["teaID"].ToString() + "'";
SqlConnection conn = new SqlConnection(connStr); //創(chuàng)建連接對(duì)象
try
{
if (conn.State.ToString() == "Closed") //連接如果關(guān)閉,打開
conn.Open();
SqlCommand cmd = new SqlCommand(SqlStr, conn);
int flag = cmd.ExecuteNonQuery();
if (flag>0)
{
lblMessage.Text = "成功修改課程信息!";
}
else
{
Response.Write("數(shù)據(jù)庫錯(cuò)誤,沒查詢到該門課程!");
Response.End();
}
}
catch (Exception ex) //異常處理
{
Response.Write("數(shù)據(jù)庫錯(cuò)誤,錯(cuò)誤原因:" + ex.Message);
Response.End();
}
finally
{
if (conn.State.ToString() == "Open") //如果連接打開,關(guān)閉
conn.Close();
}
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -