Call stored procedure in Asp.Net using C#.Net


In this post, we will discuss how to call a stored procedure in asp.net using C#.Net code. In this example, it will take one input parameter as empid and will return the result records for the particular empid.
Below is the full code:
       string connectionString = “Your connection string goes here!”;
        SqlConnection con = new SqlConnection(connectionString);
        SqlCommand cmd = new SqlCommand(“SP_NameOfYourSP”, con);
        cmd.CommandType = CommandType.StoredProcedure;
        cmd.Parameters.AddWithValue(“@empid”, SqlDbType.Int).Value = 12345;
        SqlDataAdapter da = new SqlDataAdapter(cmd);
        DataSet ds = new DataSet();
        try
        {
            con.Open();
            da.Fill(ds, “Authors”);
        }
        catch (Exception ex)
        {
            throw;
        }
        finally
        {
            con.Close();
        }
Check out Best Alternative to InfoPath -> Try Now

FREE SHAREPOINT 2019 PDF


New to Office 365 SharePoint Online? Get Office 365 Enterprise E3 Subscription & Try out all the features

(Installation & Features)



About Bijay Kumar

I am Bijay from Odisha, India. Currently working in my own venture TSInfo Technologies in Bangalore, India. I am Microsoft Office Servers and Services (SharePoint) MVP (5 times). I works in SharePoint 2016/2013/2010, SharePoint Online Office 365 etc. Check out My MVP Profile.. I also run popular SharePoint web site SharePointSky.com

View all posts by Bijay Kumar →