In this post i am going to show how to deal with Data returned by Stored procedure in ASP.NET Application
The SP is..
create procedure MultiSelectStm
As
Begin
select * from Emp
select * from Dept
End
If you want handle with DataAdapter ..
SqlConnection con = new SqlConnection(@"server=RAJI-PC\SQLEXPRESS;Initial Catalog=raji;integrated Security=True");
SqlCommand cmd = new SqlCommand("MultiSelectStm", con);
cmd.CommandType = CommandType.StoredProcedure;
SqlDataAdapter da = new SqlDataAdapter();
da.SelectCommand = cmd;
DataSet ds=new DataSet();
con.Open();
da.Fill(ds);
con.Close();
GridView1.DataSource = ds.Tables[0];
GridView1.DataBind();
GridView2.DataSource = ds.Tables[1];
GridView2.DataBind();
If you want handle with DataReader ..
SqlConnection con = new SqlConnection(@"server=RAJI-PC\SQLEXPRESS;Initial Catalog=raji;integrated Security=True");
con.Open();
SqlCommand cmd = new SqlCommand("MultiSelectStm", con);
cmd.CommandType = CommandType.StoredProcedure;
SqlDataReader dr = cmd.ExecuteReader();
bool more = true;
while(more)
{
while (dr.Read())
{
for (int i = 0; i <dr.FieldCount;i++)
{
Response.Write(dr[i].ToString() + " ");
}
Response.Write("<br>");
}
more= dr.NextResult();//control goes to next Set of Records
}
Comments more encourages me to post more Articles..
0 comments:
Respects for your's Questions & Opinions