.NET中Delete的应用

1. VIEW层
protected void gv_UserInfoList_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
    try
    {
        connection = SqlDBHelper.GetNewSqlConnection(DB.ConnectionString);

        if (gv_UserInfoList.DataKeys[e.RowIndex].Value.ToString() == ((MT_TW_UserInfo)Session["oUserInfo"]).UserID.ToString())
        {
            ShowMsg(MProperties_UserInfo.sUserInfo_Delete_SelfFailure);
            return;
        }

        BT_TW_UserInfo.UserInfo_Delete(connection, Convert.ToInt32(gv_UserInfoList.DataKeys[e.RowIndex].Value));
        ShowMsg(MProperties_UserInfo.sUserInfo_Delete_Success);
        ShowUserInfo2GridView();

    }
    catch (Exception ex)
    {
        ShowMsg(ex.ToString());
    }
    finally
    {
        SqlDBHelper.Close(connection);
    }
}


2. BUSINESS层
//====================================================================================
/// <summary>
/// 根据UserID,完成UserInfo的删除
/// </summary>
/// <returns></returns>
/// <originated>Shawn Qiu</originated>
/// <date>2010-04-01</date>
public static void UserInfo_Delete(SqlConnection connection, int iUserID)
{
    ArrayList arrSql = new ArrayList();
    arrSql.Add(SQL_UserInfo_Delete(iUserID));
    //事务执行
    SqlDBHelper.ExecuteNonQuery_Trans(connection, CommandType.Text, arrSql);

}//end of Function:UserInfo_Delete(SqlConnection connection, int iUserID)

//====================================================================================
/// <summary>
/// 构造Delete的基本数据的SQL语句
/// </summary>
/// <returns>SQL语句</returns>
/// <originated>Shawn Qiu</originated>
/// <date>2010-04-01</date>
private static string SQL_UserInfo_Delete(int iUserID)
{
    return string.Format(@"DELETE {0} WHERE {1}='{2}'"

        , MT_TW_UserInfo.TableName

        , MT_TW_UserInfo.FldName.UserID
        , iUserID

        );

}//end of Function:SQL_UserInfo_Delete(int iUserID)



你可能感兴趣的:(sql,C++,c,.net,C#)