日期:2014-05-19  浏览次数:20633 次

asp.net类(.vb)中sql语句及.aspx中如何获取值的问题
#################   begin:   类文件Magazine.vb     ##########################

Imports   Microsoft.VisualBasic
Imports   System.Data.SqlClient

Public   Class   Magazine
    Private   _MagazineID   As   Nullable(Of   Integer)   =   Nothing
    Private   _M_No   As   String
    Private   _Prol_Title   As   String

#Region   "Database   fields   as   properties "
    Public   ReadOnly   Property   EmployeeID()   As   Nullable(Of   Integer)
        Get
            Return   _MagazineID
        End   Get
    End   Property

    Public   Property   M_N0()   As   String
        Get
            Return   _M_No
        End   Get
        Set(ByVal   value   As   String)
            _M_No   =   value
        End   Set
    End   Property

    Public   Property   Prol_Title()   As   String
        Get
            Return   _Prol_Title
        End   Get
        Set(ByVal   value   As   String)
            _Prol_Title   =   value
        End   Set
    End   Property
#End   Region

    Private   Const   conn   As   String   =   "server=localhost;database=cla; "   &   _
                                "User   ID=sa;password=password; "

    Public   Shared   Function   SelectMagazine(ByVal   MagazineID   As   Integer)   As   Magazine
        Const   sql   As   String   =   "select   top   1   MagazineID,   M_No,   prol_title   "   &   _
                                                "from   magazine   where   MagazineID={0} "
        Dim   result   As   Magazine   =   Nothing
        Try
            'Open   connection
            Using   cn   As   New   SqlConnection(conn)
                Using   cmd   As   New   SqlCommand(String.Format(sql,   MagazineID.ToString),   cn)
                    cn.Open()
                    Using   dr   As   SqlDataReader   =   _