Friday, December 17, 2010

No Of Select Statements In Stored Procedure:-.NET

0 comments 12/17/2010
Sign up to receive our site updates!
A Stored Procedure with how no of select statements then the SP returns the That many no of tables.
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..
Your Ad Here

0 comments:

Respects for your's Questions & Opinions

  • Friends
  •  

    Recent Posts

    Copyright 2008 All Rights Reserved Tech Tasks Template by Rajesh Kumar Chekuri