Public Function GetNewsTopics() As String Dim oConnection As SqlConnection Dim oCommand As SqlCommand Dim oDataReader As SqlDataReader Dim IsConnection As Boolean = True
While IsConnection Try oConnection = New SqlConnection(DB("TeleLet")) oConnection.Open() oCommand = New SqlCommand With oCommand .CommandText = "spGetNewsTopics" .CommandType = CommandType.StoredProcedure .Connection = oConnection oDataReader = .ExecuteReader(CommandBehavior.CloseConnection) End With
Dim output As String While oDataReader.Read output = (oDataReader.GetInt32(0) & ", " & oDataReader.GetString(1)) End While
Return output Catch ex As Exception LogErrorEvent(ex.Message) Finally oDataReader.Close() End Try End While End Function
øhm bliver oDataReader.Close() kaldt, når den står efter "return output" ? Normalt så fanger jeg eventuelle fejl, lukker databasen, og thrower så den samme fejl igen (evt. med en modificeret besked). Dette for netop at fange fejlen i den metode hvor jeg kalder min metode. Det gør det også nemmere at se hvis der går noget galt inde i mine "lukkede" DLL'er.
Public Function GetNewsTopics() As String Dim oConnection As SqlConnection Dim oCommand As SqlCommand Dim oDataReader As SqlDataReader Dim IsConnection As Boolean = True
While IsConnection Try oConnection = New SqlConnection(DB("TeleLet")) oConnection.Open() oCommand = New SqlCommand With oCommand .CommandText = "spGetNewsTopics" .CommandType = CommandType.StoredProcedure .Connection = oConnection oDataReader = .ExecuteReader(CommandBehavior.CloseConnection) End With
IsConnection = False
Dim output As String While oDataReader.Read output = (oDataReader.GetInt32(0) & ", " & oDataReader.GetString(1)) End While
Return output oDataReader.Close() Catch ex As Exception LogErrorEvent(ex.Message) Throw ex End Try End While End Function
nu får jeg denne fejl:
Fejl besked: DataBinder.Eval: 'System.Char' does not contain a property with the name Topic.
Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.