Monday, May 14, 2012

Retorna DataSet

Public Function RetornaReport(ByVal sSQL As String, Optional ByVal sSortBy As String = "", Optional ByVal sSortDirection As String = "") As DataSet

Dim str As New StringBuilder
Dim strResultado As New StringBuilder
Dim cmd As New SqlCommand
Dim conn As New SqlConnection

conn.ConnectionString=ConfigurationManager.ConnectionStrings("MyConnectionString").ConnectionString

cmd.Connection = conn str.Append(sSQL)
cmd.CommandText = str.ToString
cmd.CommandType = CommandType.Text
conn.Open()
Dim Adapter As New SqlDataAdapter(cmd)
Dim ds As New DataSet
Adapter.Fill(ds)
conn.Close()
conn.Dispose()
Adapter.Dispose()
cmd.Dispose()
Return ds

End Function

No comments: