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>iEintragnr</LI> </UL> Properties set after a succesful call of this method: <UL> <LI>iErrorCode</LI> <LI>iEintragnr</LI> <LI>sTabelle</LI> <LI>sTabellenspalte</LI> <LI>sSpalte</LI> <LI>bReadonly</LI> <LI>bAlsHacken</LI> <LI>iBreite</LI> <LI>iReihenfolge</LI> <LI>sTiptext</LI> <LI>bAktiv</LI> <LI>daErstellt_am</LI> <LI>daMutiert_am</LI> <LI>iMutierer</LI> <LI>iMandantnr</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_spalten_SelectOne]"
scmCmdToExecute.CommandType = CommandType.StoredProcedure
Dim dtToReturn As DataTable = new DataTable("spalten")
Dim sdaAdapter As SqlDataAdapter = new SqlDataAdapter(scmCmdToExecute)
' // Use base class' connection object
scmCmdToExecute.Connection = m_scoMainConnection
Try
scmCmdToExecute.Parameters.Add(new SqlParameter("@ieintragnr", SqlDbType.Int, 4, ParameterDirection.Input, False, 10, 0, "", DataRowVersion.Proposed, m_iEintragnr))
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_spalten_SelectOne' reported the ErrorCode: " & m_iErrorCode.ToString())
End If
If dtToReturn.Rows.Count > 0 Then
m_iEintragnr = New SqlInt32(CType(dtToReturn.Rows(0)("eintragnr"), Integer))
If dtToReturn.Rows(0)("tabelle") Is System.DBNull.Value Then
m_sTabelle = SqlString.Null
Else
m_sTabelle = New SqlString(CType(dtToReturn.Rows(0)("tabelle"), String))
End If
If dtToReturn.Rows(0)("tabellenspalte") Is System.DBNull.Value Then
m_sTabellenspalte = SqlString.Null
Else
m_sTabellenspalte = New SqlString(CType(dtToReturn.Rows(0)("tabellenspalte"), String))
End If
If dtToReturn.Rows(0)("spalte") Is System.DBNull.Value Then
m_sSpalte = SqlString.Null
Else
m_sSpalte = New SqlString(CType(dtToReturn.Rows(0)("spalte"), String))
End If
m_bReadonly = New SqlBoolean(CType(dtToReturn.Rows(0)("Readonly"), Boolean))
m_bAlsHacken = New SqlBoolean(CType(dtToReturn.Rows(0)("alsHacken"), Boolean))
If dtToReturn.Rows(0)("Breite") Is System.DBNull.Value Then
m_iBreite = SqlInt32.Null
Else
m_iBreite = New SqlInt32(CType(dtToReturn.Rows(0)("Breite"), Integer))
End If
If dtToReturn.Rows(0)("Reihenfolge") Is System.DBNull.Value Then
m_iReihenfolge = SqlInt32.Null
Else
m_iReihenfolge = New SqlInt32(CType(dtToReturn.Rows(0)("Reihenfolge"), Integer))
End If
If dtToReturn.Rows(0)("tiptext") Is System.DBNull.Value Then
m_sTiptext = SqlString.Null
Else
m_sTiptext = New SqlString(CType(dtToReturn.Rows(0)("tiptext"), String))
End If
m_bAktiv = New SqlBoolean(CType(dtToReturn.Rows(0)("aktiv"), Boolean))
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
End If
Return dtToReturn
Catch ex As Exception
' // some error occured. Bubble it to caller and encapsulate Exception object
Throw New Exception("clsSpalten::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