.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Articles >> C# >> Post New Resource Bookmark and Share   

 Subscribe to Articles

How to call a Select statement Stored Procedure using SqlDataAdapter?

Posted By:Syed Shakeer Hussain       Posted Date: August 17, 2009    Points: 25    Category: C#    URL: http://www.dotnetspark.com  
 

Creating a select statement storedprocedure:

CREATE PROCEDURE selectemp1

 AS
select * from emp

Here 'selectemp1' is a procedure name and emp is the Table name.

How to call a Procedure name usign SqlDataAdapter and display the data in Gridview:

SqlConnection conn = new SqlConnection("Data Source=INTHIYAAZ;Initial Catalog=shakeer;User ID=sa;Password=sa");
        conn.Open();

//calling the stored procedure name 'selectemp1' in sqlcommand
        SqlCommand cmd = new SqlCommand("selectemp1",conn );
        SqlDataAdapter adapter = new SqlDataAdapter(cmd );
        DataSet ds = new DataSet();
        adapter.Fill(ds);
        GridView1.DataSource = ds.Tables[0];
        GridView1.DataBind();

output of the Gridview Image:

Thanks for Reading Article!

Syed Shakeer Hussain

 

 Subscribe to Articles

     

Further Readings:

Responses

No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More Articles on C#, ASP.Net, Vb.Net, SQL Server and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend