asp.net

位置:IT落伍者 >> asp.net >> 浏览文章

ASP.NET项目开发指南:房间信息管理页面(2)[2]


发布日期:2024年04月04日
 
ASP.NET项目开发指南:房间信息管理页面(2)[2]

程序 ST_RoomsManModuleascxcs

protected void GridView_Delete(Object sender

GridViewDeleteEventArgs E)

{

//从文件WebConfig中读取连接字符串

string ST_sqldb =

ConfigurationSettingsAppSettings[ConnectionString];

//连接ST_GinShopManage数据库

SqlConnection ST_Conn = new SqlConnection (ST_sqldb)

ST_ConnOpen ()

//创建ST_mycommand对象调用存储过程

SqlCommand ST_mycommand = new SqlCommand (ST_DeleteRoomST_Conn)

ST_mycommandCommandType=CommandTypeStoredProcedure;

ST_mycommandParameters Add (@RoomIdSqlDbTypeInt )

//从dg_RoomsList中获取UserId值

ST_mycommandParameters[@RoomId]Value =

dg_RoomsListDataKeys[ERowIndex]ValueToString()

ST_mycommandExecuteNonQuery ()

dg_RoomsListEditIndex =;

//更新dg_RoomsList

Show_RoomsList()

}

protected void GridView_Page(Object sender GridViewPageEventArgs E)

{

dg_RoomsListPageIndex =ENewPageIndex ;

Show_RoomsList()

}

private void search_Click(object sender SystemEventArgs e)

{

//从文件WebConfig中读取连接字符串

string ST_sqldb =

ConfigurationSettingsAppSettings[ConnectionString];

//连接ST_GinShopManage数据库

SqlConnection ST_Conn = new SqlConnection (ST_sqldb)

//创建SqlDataAdapter对象调用存储过程ST_ShowRoomsInfo

SqlDataAdapter ST_myadapter = new SqlDataAdapter

ST_ShowRoomByIdST_Conn)

ST_myadapterSelectCommandCommandType

=CommandTypeStoredProcedure;

ST_myadapterSelectCommandParameters Add

@RoomIdSqlDbTypeInt)

ST_myadapterSelectCommandParameters [@RoomId]Value

=RoomIdTextBoxTextTrim()

//创建并填充DataSet

DataSet ds = new DataSet ()

ST_myadapterFill (ds)

dg_RoomsListDataSource =ds;

dg_RoomsListDataBind ()

ST_ConnClose ()

}

private void ShowAll_Click(object sender SystemEventArgs e)

{

Show_RoomsList()

}

【代码说明】代码第行很关键用来获取被删除行的IDERowIndex用来获取用户选择的是第几行DataKeys[ERowIndex]Value表示当前行中主键的值代码第行说明获取数据使用的是存储过程代码第~行将数据绑定到dg_RoomsList

返回目录ASPNET项目开发指南

编辑推荐

ASPNET MVC 框架揭秘

ASPNET开发宝典

ASP NET开发培训视频教程

[] []

               

上一篇:ASP.NET项目开发指南:Blog数据库连接编写

下一篇:ASP.NET项目开发指南:房间信息管理页面(2)[1]