📄 st_rcategoryedit.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 ST_RCategoryEdit : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
this.lblId.Text = Request.QueryString["RCategoryId"].ToString();
this.lblInfo.Visible = false;
SetDataBind();
}
}
public void SetDataBind()
{
int CategoryId=System.Convert.ToInt32(this.lblId.Text);
SqlConnection ST_myCon = new SqlConnection(ConfigurationSettings.AppSettings["ConnectionString"]);
SqlCommand ST_mycommand = new SqlCommand();
ST_mycommand.Connection = ST_myCon;
string str = "select * from ST_RoomCategory where ST_RCategoryId=@RCategoryId";
ST_mycommand.CommandText = str;
ST_mycommand.Parameters.Add("@RCategoryId", SqlDbType.Int);
ST_mycommand.Parameters["@RCategoryId"].Value = System.Convert.ToInt32(this.lblId.Text);
try
{
ST_myCon.Open();
SqlDataReader dr = ST_mycommand.ExecuteReader();
if (dr.Read())
{
this.txtCateName.Text = dr["ST_Name"].ToString();
this.txtArea.Text = dr["ST_Area"].ToString();
this.txtBedNum.Text = dr["ST_BedNum"].ToString();
this.txtPrice.Text = dr["ST_Price"].ToString();
this.rabAirCondition.SelectedIndex = int.Parse(dr["ST_AirCondition"].ToString());
this.rabTv.SelectedIndex = int.Parse(dr["ST_TV"].ToString());
}
}
catch (SqlException exx)
{
throw (exx);
}
finally
{
ST_myCon.Close();
}
}
protected void Button1_Click(object sender, EventArgs e)
{
if (Page.IsValid)
{
SqlConnection ST_myCon = new SqlConnection(ConfigurationSettings.AppSettings["ConnectionString"]);
SqlCommand ST_mycommand = new SqlCommand();
ST_mycommand.Connection = ST_myCon;
string str = "update ST_RoomCategory set ST_Name=@Name,ST_Area=@Area,ST_BedNum=@BedNum,ST_Price=@Price,ST_AirCondition=@AirCondition,ST_TV=@TV where ST_RCategoryId=@RCategoryId";
ST_mycommand.CommandText = str;
ST_mycommand.Parameters.Add("@RCategoryId", SqlDbType.Int);
ST_mycommand.Parameters.Add("@Name", SqlDbType.VarChar, 50);
ST_mycommand.Parameters.Add("@Area", SqlDbType.Float);
ST_mycommand.Parameters.Add("@BedNum", SqlDbType.Int);
ST_mycommand.Parameters.Add("@Price", SqlDbType.Money);
ST_mycommand.Parameters.Add("@AirCondition", SqlDbType.Int);
ST_mycommand.Parameters.Add("@TV", SqlDbType.Int);
ST_mycommand.Parameters["@RCategoryId"].Value = int.Parse(this.lblId.Text);
ST_mycommand.Parameters["@Name"].Value=this.txtCateName.Text.ToString();
ST_mycommand.Parameters["@Area"].Value = System.Convert.ToDouble(this.txtArea.Text);
ST_mycommand.Parameters["@BedNum"].Value = int.Parse(this.txtBedNum.Text);
ST_mycommand.Parameters["@Price"].Value = System.Convert.ToDouble(this.txtPrice.Text);
ST_mycommand.Parameters["@AirCondition"].Value = this.rabAirCondition.SelectedIndex;
ST_mycommand.Parameters["@TV"].Value = this.rabTv.SelectedIndex;
try
{
ST_myCon.Open();
ST_mycommand.ExecuteNonQuery();
this.lblInfo.Visible = true;
this.lblId.Style["color"] = "green";
this.lblInfo.Text = "修改成功";
}
catch(SqlException exx)
{
this.lblInfo.Visible = true;
this.lblInfo.Style["color"] = "red";
this.lblInfo.Text="出错了:"+exx.Message;
}
finally
{
ST_myCon.Close();
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -