.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 >> Code Snippets >> ADO.NET >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

Call Store Procedure

Posted By:shiv chandra       Posted Date: June 29, 2011    Points: 40    Category: ADO.NET    URL: http://www.dotnetspark.com  

This code sample to show how to Call Store Procedure using ADO.NET using C#
 

protected void Page_Load(object sender, EventArgs e)
{
    string DataSource = "Specify Your Data Source";
    string Database = "Specify your database";   
    SqlConnection Con = new SqlConnection("Data Source=" + DataSource + ";Initial Catalog=" + Database + ";Integrated Security=True");

    try
    {
        Con.Open();
        SqlCommand Cmd = new SqlCommand("Name Of Store Procedure", Con);
        Cmd.CommandType = CommandType.StoredProcedure;
        SqlDataAdapter Adapter = new SqlDataAdapter(Cmd);

        DataTable Tables = new DataTable();
        Adapter.Fill(Tables);

        Grid.DataSource = Tables;
        Grid.DataBind();
    }
    catch ( SqlException ex)
    {
        Response.Write(ex.Message);
    }
}
Before using above code, please change Datasource, database and name of stored procedure.

Regards,
Shiva


     

Further Readings:

Responses

No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More code samples in C#, ASP.Net, Vb.Net and more Here

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