程序 ST_RCatgEditModuleascxcs
private void Submit_Click(object sender SystemEventArgs e)
{
if(PageIsValid )
{
//从文件WebConfig中读取连接字符串
string ST_sqldb =
ConfigurationSettingsAppSettings[ConnectionString];
//连接ST_GinShopManage数据库
SqlConnection ST_Conn = new SqlConnection (ST_sqldb)
ST_ConnOpen ()
//定义SQL语句
String updatesql=update ST_RoomCategory set
ST_Name=@NameST_Area=@AreaST_BedNum=@BedNum
ST_Price=@PriceST_AirCondition=@AirCondition
ST_TV=@TV where ST_RCategoryId = @RCategoryId;
//利用Command对象调用updatesql
SqlCommand ST_mycommand=new SqlCommand (updatesqlST_Conn)
//向存储过程中添加参数
ST_mycommandParameters Add (@RCategoryIdSqlDbTypeInt)
ST_mycommandParameters Add (@NameSqlDbTypeVarChar)
ST_mycommandParameters Add (@AreaSqlDbTypeFloat)
ST_mycommandParameters Add (@BedNumSqlDbTypeInt)
ST_mycommandParameters Add (@PriceSqlDbTypeMoney)
ST_mycommandParameters Add (@AirConditionSqlDbTypeInt)
ST_mycommandParameters Add (@TVSqlDbTypeInt)
//给存储过程的参数赋值
ST_mycommandParameters [@RCategoryId]Value
=intParse(RCategoryIdLabelText)
ST_mycommandParameters [@Name]Value
=RCatgNameTextBoxTextTrim()
ST_mycommandParameters [@Area]Value
=ConvertToDouble(AreaTextBoxTextTrim())
ST_mycommandParameters [@BedNum]Value
=intParse(BedNumTextBoxTextTrim())
ST_mycommandParameters [@Price]Value
=ConvertToDouble(PriceTextBoxTextTrim())
ST_mycommandParameters [@AirCondition]Value
=AirConditionListSelectedIndex;
ST_mycommandParameters [@TV]Value =TvListSelectedIndex;
try
{
//执行SQL语句并设置修改成功信息
ST_mycommandExecuteNonQuery()
ShowMsgText=房间类型信息修改成功;
ShowMsgStyle[color]=green;}
catch(SqlException error)
{
ShowMsgText=修改未成功请稍后再试原因+errorMessage;
ShowMsgStyle[color]=red;
}
//关闭连接
ST_ConnClose()
}
}
【代码说明】从代码第~行可以看出创建了一些参数这些参数针对ST_RoomCategory表中的每一个字段然后在代码第~行为这些参数赋值最后通过代码第行执行SQL语句
说明SqlException封装的是访问SQL Server时发生的错误
返回目录ASPNET项目开发指南
编辑推荐
ASPNET MVC 框架揭秘
ASPNET开发宝典
ASP NET开发培训视频教程
[] []