Purpose: Select method. This method will Select one existing row from the database, based on the Primary Key.
[Visual Basic] Public Overrides Function SelectOne() As DataTable
DataTable object if succeeded, otherwise an Exception is thrown.
Properties needed for this method: <UL> <LI>iDokumentNr</LI> </UL> Properties set after a succesful call of this method: <UL> <LI>iErrorCode</LI> <LI>iDokumentNr</LI> <LI>iKeyValue</LI> <LI>iDokType</LI> <LI>iDokumenttypNr</LI> <LI>sBezeichnung</LI> <LI>sBeschreibung</LI> <LI>sFilename</LI> <LI>sOriginalFilename_incl_Path</LI> <LI>sVersion</LI> <LI>sVersionsNr</LI> <LI>daVersionsdatum</LI> <LI>daErstellt_am</LI> <LI>daMutiert_am</LI> <LI>iMutierer</LI> <LI>bAktiv</LI> <LI>iSecurityLevelNr</LI> <LI>blobDocImage</LI> </UL> Will fill all properties corresponding with a field in the table with the value of the row selected.
[Visual Basic] Overrides Public Function SelectOne() As DataTable
Dim scmCmdToExecute As SqlCommand = New SqlCommand()
scmCmdToExecute.CommandText = "dbo.[pr_Dokument_SelectOne]"
scmCmdToExecute.CommandType = CommandType.StoredProcedure
Dim dtToReturn As DataTable = new DataTable("Dokument")
Dim sdaAdapter As SqlDataAdapter = new SqlDataAdapter(scmCmdToExecute)
' // Use base class' connection object
scmCmdToExecute.Connection = m_scoMainConnection
Try
scmCmdToExecute.Parameters.Add(new SqlParameter("@iDokumentNr", SqlDbType.Int, 4, ParameterDirection.Input, False, 10, 0, "", DataRowVersion.Proposed, m_iDokumentNr))
scmCmdToExecute.Parameters.Add(new SqlParameter("@iErrorCode", SqlDbType.Int, 4, ParameterDirection.Output, True, 10, 0, "", DataRowVersion.Proposed, m_iErrorCode))
If m_bMainConnectionIsCreatedLocal Then
' // Open connection.
m_scoMainConnection.Open()
Else
If m_cpMainConnectionProvider.bIsTransactionPending Then
scmCmdToExecute.Transaction = m_cpMainConnectionProvider.stCurrentTransaction
End If
End If
' // Execute query.
sdaAdapter.Fill(dtToReturn)
m_iErrorCode = New SqlInt32(CType(scmCmdToExecute.Parameters.Item("@iErrorCode").Value, SqlInt32))
If Not m_iErrorCode.Equals(New SqlInt32(LLBLError.AllOk)) Then
' // Throw error.
Throw New Exception("Stored Procedure 'pr_Dokument_SelectOne' reported the ErrorCode: " & m_iErrorCode.ToString())
End If
If dtToReturn.Rows.Count > 0 Then
m_iDokumentNr = New SqlInt32(CType(dtToReturn.Rows(0)("DokumentNr"), Integer))
If dtToReturn.Rows(0)("KeyValue") Is System.DBNull.Value Then
m_iKeyValue = SqlInt32.Null
Else
m_iKeyValue = New SqlInt32(CType(dtToReturn.Rows(0)("KeyValue"), Integer))
End If
If dtToReturn.Rows(0)("DokType") Is System.DBNull.Value Then
m_iDokType = SqlInt32.Null
Else
m_iDokType = New SqlInt32(CType(dtToReturn.Rows(0)("DokType"), Integer))
End If
If dtToReturn.Rows(0)("DokumenttypNr") Is System.DBNull.Value Then
m_iDokumenttypNr = SqlInt32.Null
Else
m_iDokumenttypNr = New SqlInt32(CType(dtToReturn.Rows(0)("DokumenttypNr"), Integer))
End If
If dtToReturn.Rows(0)("Bezeichnung") Is System.DBNull.Value Then
m_sBezeichnung = SqlString.Null
Else
m_sBezeichnung = New SqlString(CType(dtToReturn.Rows(0)("Bezeichnung"), String))
End If
If dtToReturn.Rows(0)("Beschreibung") Is System.DBNull.Value Then
m_sBeschreibung = SqlString.Null
Else
m_sBeschreibung = New SqlString(CType(dtToReturn.Rows(0)("Beschreibung"), String))
End If
If dtToReturn.Rows(0)("Filename") Is System.DBNull.Value Then
m_sFilename = SqlString.Null
Else
m_sFilename = New SqlString(CType(dtToReturn.Rows(0)("Filename"), String))
End If
If dtToReturn.Rows(0)("OriginalFilename_incl_Path") Is System.DBNull.Value Then
m_sOriginalFilename_incl_Path = SqlString.Null
Else
m_sOriginalFilename_incl_Path = New SqlString(CType(dtToReturn.Rows(0)("OriginalFilename_incl_Path"), String))
End If
If dtToReturn.Rows(0)("Version") Is System.DBNull.Value Then
m_sVersion = SqlString.Null
Else
m_sVersion = New SqlString(CType(dtToReturn.Rows(0)("Version"), String))
End If
If dtToReturn.Rows(0)("VersionsNr") Is System.DBNull.Value Then
m_sVersionsNr = SqlString.Null
Else
m_sVersionsNr = New SqlString(CType(dtToReturn.Rows(0)("VersionsNr"), String))
End If
If dtToReturn.Rows(0)("Versionsdatum") Is System.DBNull.Value Then
m_daVersionsdatum = SqlDateTime.Null
Else
m_daVersionsdatum = New SqlDateTime(CType(dtToReturn.Rows(0)("Versionsdatum"), Date))
End If
If dtToReturn.Rows(0)("Erstellt_am") Is System.DBNull.Value Then
m_daErstellt_am = SqlDateTime.Null
Else
m_daErstellt_am = New SqlDateTime(CType(dtToReturn.Rows(0)("Erstellt_am"), Date))
End If
If dtToReturn.Rows(0)("Mutiert_am") Is System.DBNull.Value Then
m_daMutiert_am = SqlDateTime.Null
Else
m_daMutiert_am = New SqlDateTime(CType(dtToReturn.Rows(0)("Mutiert_am"), Date))
End If
If dtToReturn.Rows(0)("Mutierer") Is System.DBNull.Value Then
m_iMutierer = SqlInt32.Null
Else
m_iMutierer = New SqlInt32(CType(dtToReturn.Rows(0)("Mutierer"), Integer))
End If
If dtToReturn.Rows(0)("Aktiv") Is System.DBNull.Value Then
m_bAktiv = SqlBoolean.Null
Else
m_bAktiv = New SqlBoolean(CType(dtToReturn.Rows(0)("Aktiv"), Boolean))
End If
If dtToReturn.Rows(0)("SecurityLevelNr") Is System.DBNull.Value Then
m_iSecurityLevelNr = SqlInt32.Null
Else
m_iSecurityLevelNr = New SqlInt32(CType(dtToReturn.Rows(0)("SecurityLevelNr"), Integer))
End If
If dtToReturn.Rows(0)("DocImage") Is System.DBNull.Value Then
m_blobDocImage = SqlBinary.Null
Else
m_blobDocImage = New SqlBinary(CType(dtToReturn.Rows(0)("DocImage"), Byte()))
End If
End If
Return dtToReturn
Catch ex As Exception
' // some error occured. Bubble it to caller and encapsulate Exception object
Throw New Exception("clsDokument::SelectOne::Error occured.", ex)
Finally
If m_bMainConnectionIsCreatedLocal Then
' // Close connection.
m_scoMainConnection.Close()
End If
scmCmdToExecute.Dispose()
sdaAdapter.Dispose()
End Try
End Function
Plattformen: Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition