?? st_roomedit.ascx.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 Context_ST_RoomEdit : System.Web.UI.UserControl
{
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
SqlConnection ST_myCon = new SqlConnection(ConfigurationSettings.AppSettings["ConnectionString"]);
SqlCommand ST_mycommand = new SqlCommand();
ST_mycommand.Connection = ST_myCon;
ST_mycommand.CommandText = "select ST_RCategoryId,ST_Name from ST_RoomCategory";
ST_myCon.Open();
SqlDataReader dl = ST_mycommand.ExecuteReader();
while (dl.Read())
{
ListItem li = new ListItem(dl["ST_Name"].ToString(), dl["ST_RCategoryId"].ToString());
this.txtCategory.Items.Add(li);
}
dl.Close();
ST_myCon.Close();
SetDataBind();
}
}
public void SetDataBind()
{
this.lblRoomId.Text = Request.QueryString["RoomId"].ToString();
int RoomId = int.Parse(this.lblRoomId.Text);
SqlConnection ST_myCon = new SqlConnection(ConfigurationSettings.AppSettings["ConnectionString"]);
SqlCommand ST_mycommand = new SqlCommand();
ST_mycommand.Connection = ST_myCon;
ST_mycommand.CommandText = "select * from RoomsInfoView where ST_RoomId=" + RoomId + "";
ST_myCon.Open();
SqlDataReader dl = ST_mycommand.ExecuteReader();
if (dl.Read())
{
this.txtCategory.Items.FindByText(dl["ST_Name"].ToString()).Selected = true;
this.txtPosition.Text = dl["ST_RPosition"].ToString();
this.txtDesc.Text = dl["ST_Description"].ToString();
}
dl.Close();
ST_myCon.Close();
}
protected void Button1_Click(object sender, EventArgs e)
{
// Response.Write(this.txtCategory.SelectedValue);
SqlConnection ST_myCon = new SqlConnection(ConfigurationSettings.AppSettings["ConnectionString"]);
SqlCommand ST_mycommand = new SqlCommand();
ST_mycommand.Connection = ST_myCon;
ST_mycommand.CommandType = CommandType.StoredProcedure;
ST_mycommand.CommandText = "ST_UpdateRoom";
ST_mycommand.Parameters.Add("@RoomId", SqlDbType.Int);
ST_mycommand.Parameters.Add("@RCategoryId", SqlDbType.Int);
ST_mycommand.Parameters.Add("@RPosition", SqlDbType.VarChar, 50);
ST_mycommand.Parameters.Add("@Description", SqlDbType.VarChar, 50);
ST_mycommand.Parameters["@RoomId"].Value = System.Convert.ToInt32(int.Parse(this.lblRoomId.Text.ToString()));
ST_mycommand.Parameters["@RCategoryId"].Value =this.txtCategory.SelectedValue;
ST_mycommand.Parameters["@RPosition"].Value = this.txtPosition.Text;
ST_mycommand.Parameters["@Description"].Value = this.txtDesc.Text;
try
{
ST_myCon.Open();
ST_mycommand.ExecuteNonQuery();
this.lblInfo.Text = "修改成功";
}
catch (SqlException exx)
{
this.lblInfo.Text = "修改失敗:" + exx.Message;
}
finally
{
ST_myCon.Close();
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -