Hi all -
Does anyone have an opinion (or even better, FACTS) as to whether the following use of a Shared Function is a good or bad practice for retrieving data into an app?
To be clear, my question is with regard to the use of the shared function, which returns a reference to a datatable to the calling code. While there a probably many debates as to the preferred use of ADO.NET objects, my question is about the Shared Method aspect. Note that the dataTable is declared within the Shared Function, so it seems to me you get a new one every time, yes?
Is there a downside to this I am missing?
Code:Public Shared Function MyData() As DataTable Dim ReturnData As New DataTable 'A silly example of retreiving some data into a datatable: Using cn As New SqlClient.SqlConnection("SomeCOnnectionString") Using cmd As New SqlClient.SqlCommand("SomeSQLString", cn) 'May or may not need params. This is just an example . . . cn.Open() Dim dr As SqlClient.SqlDataReader dr = cmd.ExecuteReader ReturnData.Load(dr) End Using End Using 'Now return THIS as the Function output: Return ReturnData End Function




Reply With Quote