Load Sql Table
Loads data from a SQL table into a DataTable using the specified connection and query parameters.
This function opens the SQL connection if it is not already open and executes a SELECT query dynamically constructed from the provided parameters. It uses iuSqlFunctions.ExecuteQueryOnDataTable(SqlConnection,String) to perform the actual query execution and data retrieval.
VB
Public Function LoadSqlTable(MyConnection As SqlConnection,
TableName As String,
Optional FieldList As String = "*",
Optional WhereCondition As String = "") As DataTable
Try
If Not MyConnection.State = ConnectionState.Open Then MyConnection.Open()
Dim szQuery As String = $"SELECT {FieldList} FROM {TableName} {WhereCondition}"
Dim dtToReturn As DataTable = ExecuteQueryOnDataTable(MyConnection, szQuery)
Return dtToReturn
Catch ex As Exception
End Try
Return Nothing
End Function