Well, if you run the SP using a
SqlCommand[
^] etc. just bind the resulting
DataTable[
^] to the
DataGridView[
^] (assigning it to
DataGridView.DataSource Property[
^]).
The
DataGridView
should now automatically populate its columns and fill the rows with the results.
It will basically look like you ran the SP using SQL Server.
Example:
DataTable dt = GetStoredProcResults();
DataGridView1.DataSource = dt;
And that's all there is to it :)
Edit:
Here is a rough example of how to get the data from a stored procedure:
SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder();
builder.DataSource = "(local)";
builder.InitialCatalog = "Northwind";
builder.IntegratedSecurity = true;
using (SqlConnection conn = new SqlConnection(builder.ToString()))
{
using (SqlCommand cmd = new SqlCommand("Ten Most Expensive Products", conn))
{
cmd.CommandType = CommandType.StoredProcedure;
using (SqlDataAdapter adapter = new SqlDataAdapter(cmd))
{
DataTable dt = new DataTable();
adapter.Fill(dt);
dataGridView1.DataSource = dt;
}
}
}
For more information see the following articles:
SqlConnection[
^]
SqlCommand[
^]
SqlDataAdapter[
^]
Note that all of the above Classes Inherit from Interfaces and base classes. OleDb, Oracle and any other database stuff works using these Interfaces and baseclasses. If you know this stuff for Sql you know it for Oracle, Access, etc. :)