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>iPersonNr</LI> </UL> Properties set after a succesful call of this method: <UL> <LI>iErrorCode</LI> <LI>iPersonNr</LI> <LI>iVertragspartnernr</LI> <LI>sName</LI> <LI>sVorname</LI> <LI>sStrasse</LI> <LI>sPostfach</LI> <LI>sPlz</LI> <LI>sOrt</LI> <LI>sTelefon</LI> <LI>sTelefax</LI> <LI>sEMail</LI> <LI>sInternet</LI> <LI>sBemerkung</LI> <LI>bAktiv</LI> <LI>daErstellt_am</LI> <LI>daMutiert_am</LI> <LI>iMutierer</LI> <LI>iMandantNr</LI> <LI>iSecurityLevelNr</LI> <LI>iPersonFunktionNr</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_Person_SelectOne]"
scmCmdToExecute.CommandType = CommandType.StoredProcedure
Dim dtToReturn As DataTable = new DataTable("Person")
Dim sdaAdapter As SqlDataAdapter = new SqlDataAdapter(scmCmdToExecute)
' // Use base class' connection object
scmCmdToExecute.Connection = m_scoMainConnection
Try
scmCmdToExecute.Parameters.Add(new SqlParameter("@iPersonNr", SqlDbType.Int, 4, ParameterDirection.Input, False, 10, 0, "", DataRowVersion.Proposed, m_iPersonNr))
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_Person_SelectOne' reported the ErrorCode: " & m_iErrorCode.ToString())
End If
If dtToReturn.Rows.Count > 0 Then
m_iPersonNr = New SqlInt32(CType(dtToReturn.Rows(0)("PersonNr"), Integer))
If dtToReturn.Rows(0)("Vertragspartnernr") Is System.DBNull.Value Then
m_iVertragspartnernr = SqlInt32.Null
Else
m_iVertragspartnernr = New SqlInt32(CType(dtToReturn.Rows(0)("Vertragspartnernr"), Integer))
End If
If dtToReturn.Rows(0)("Name") Is System.DBNull.Value Then
m_sName = SqlString.Null
Else
m_sName = New SqlString(CType(dtToReturn.Rows(0)("Name"), String))
End If
If dtToReturn.Rows(0)("Vorname") Is System.DBNull.Value Then
m_sVorname = SqlString.Null
Else
m_sVorname = New SqlString(CType(dtToReturn.Rows(0)("Vorname"), String))
End If
If dtToReturn.Rows(0)("Strasse") Is System.DBNull.Value Then
m_sStrasse = SqlString.Null
Else
m_sStrasse = New SqlString(CType(dtToReturn.Rows(0)("Strasse"), String))
End If
If dtToReturn.Rows(0)("Postfach") Is System.DBNull.Value Then
m_sPostfach = SqlString.Null
Else
m_sPostfach = New SqlString(CType(dtToReturn.Rows(0)("Postfach"), String))
End If
If dtToReturn.Rows(0)("Plz") Is System.DBNull.Value Then
m_sPlz = SqlString.Null
Else
m_sPlz = New SqlString(CType(dtToReturn.Rows(0)("Plz"), String))
End If
If dtToReturn.Rows(0)("Ort") Is System.DBNull.Value Then
m_sOrt = SqlString.Null
Else
m_sOrt = New SqlString(CType(dtToReturn.Rows(0)("Ort"), String))
End If
If dtToReturn.Rows(0)("Telefon") Is System.DBNull.Value Then
m_sTelefon = SqlString.Null
Else
m_sTelefon = New SqlString(CType(dtToReturn.Rows(0)("Telefon"), String))
End If
If dtToReturn.Rows(0)("Telefax") Is System.DBNull.Value Then
m_sTelefax = SqlString.Null
Else
m_sTelefax = New SqlString(CType(dtToReturn.Rows(0)("Telefax"), String))
End If
If dtToReturn.Rows(0)("EMail") Is System.DBNull.Value Then
m_sEMail = SqlString.Null
Else
m_sEMail = New SqlString(CType(dtToReturn.Rows(0)("EMail"), String))
End If
If dtToReturn.Rows(0)("Internet") Is System.DBNull.Value Then
m_sInternet = SqlString.Null
Else
m_sInternet = New SqlString(CType(dtToReturn.Rows(0)("Internet"), String))
End If
If dtToReturn.Rows(0)("Bemerkung") Is System.DBNull.Value Then
m_sBemerkung = SqlString.Null
Else
m_sBemerkung = New SqlString(CType(dtToReturn.Rows(0)("Bemerkung"), String))
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)("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)("MandantNr") Is System.DBNull.Value Then
m_iMandantNr = SqlInt32.Null
Else
m_iMandantNr = New SqlInt32(CType(dtToReturn.Rows(0)("MandantNr"), Integer))
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)("PersonFunktionNr") Is System.DBNull.Value Then
m_iPersonFunktionNr = SqlInt32.Null
Else
m_iPersonFunktionNr = New SqlInt32(CType(dtToReturn.Rows(0)("PersonFunktionNr"), Integer))
End If
End If
Return dtToReturn
Catch ex As Exception
' // some error occured. Bubble it to caller and encapsulate Exception object
Throw New Exception("clsPerson::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