Why?
A simple binding can't be an option???
public static DataTable GetData()
{
DataTable table = new DataTable();
string query = @"SELECT * FROM tblClients";
using (SqlConnection cn = new SqlConnection(Configuration.DefaultConnectionString))
{
using (SqlCommand cmd = new SqlCommand(query, cn))
{
cn.Open();
using (SqlDataReader reader = cmd.ExecuteReader(CommandBehavior.CloseConnection))
{
table.Load(reader);
}
}
}
return table;
}
MyGrid.DataSource = GetData();
MyGrid.DataBind();
VB.NET
Public Shared Function GetData() As DataTable
Dim table As New DataTable()
Using cn As New SqlConnection("your connection string")
Using cmd As New SqlCommand("SELECT * FROM tblClients", cn)
cn.Open()
Using reader As SqlDataReader = cmd.ExecuteReader(CommandBehavior.CloseConnection)
table.Load(reader)
End Using
End Using
End Using
Return table
End Function
Cheers