Go to DotNetFunda.com
 Online : 629 |  Welcome, Guest!   Login
 
Home > Articles > ASP.NET > Working with Stored Procedures using asp.net

Submit Article | Articles Home | Search Articles |

Working with Stored Procedures using asp.net

1 vote(s)
Rating: 5 out of 5
red flag  Posted on: 9/9/2009 7:40:30 AM by G_arora | Views: 1019 | Category: ASP.NET | Level: Beginner


Stored procedure helps to make your work easy. With the help of these you just have to supply some parameters only.



Introduction
Stored procedure helps to make your work easy. With the help of these you just have to supply some parameters only. 

In the following code, I tried to explain the working with Stored procedure.
namespace CSharp.AStepAhead.usingstoredprocedure
{
    public class usingstoredprocedure
    {
        static string myConStr = "server=(local); integrated security=SSPI;database=HRnPAYROLL";
        static SqlConnection myCon;
        static SqlCommand myCmd;
        static SqlDataReader myDr;
        public static void Main()
        {
            int i = 0;
            string empId, fnm, lnm, age;

            for (; ; )
            {
                Console.Clear();

                Console.Write("\n 1 Insert Record(s)");
                Console.Write("\n 2 Update Record(s)");
                Console.Write("\n 3 Delete Record(s)");
                Console.Write("\n 4 Display Record(s)");
                Console.Write("\n 5 Display Record(s) By Employee ID");
                Console.Write("\n 6 Display Record(s) By Name Criteria");
                Console.Write("\n 7 Exit\n");
                Console.Write("\n Select your option [1-7]: ");
                i = int.Parse(Console.ReadLine());
                if (i <= 0)
                {
                    Console.WriteLine("\a Invalid Selection!");
                    Console.ReadLine();
                    continue;
                }
                if (i < 7)
                {
                    switch (i)
                    {
                        case 1: //Insert record
                            {
                                Console.Write(" Enter Employee Id:");
                                empId = Console.ReadLine();
                                Console.Write(" Enter First Name:");
                                fnm = Console.ReadLine();
                                Console.Write(" Enter Last Name:");
                                lnm = Console.ReadLine();
                                Console.Write(" Enter Age:");
                                age = Console.ReadLine();
                                Console.WriteLine("\n " + usingstoredprocedure.InsertEmployee(empId, fnm, lnm, age));
                                Console.ReadLine();
                                break;
                            }

                        case 2:
                            {
                                Console.Write(" Enter Employee Id:");
                                empId = Console.ReadLine();
                                Console.Write(" Enter First Name:");
                                fnm = Console.ReadLine();
                                Console.Write(" Enter Last Name:");
                                lnm = Console.ReadLine();
                                Console.Write(" Enter Age:");
                                age = Console.ReadLine();
                                Console.WriteLine("\n " + usingstoredprocedure.UpdateEmployee(empId, fnm, lnm, age));
                                Console.ReadLine();
                                break;
                            }

                        case 3:
                            {
                                Console.Write(" Enter Employee Id:");
                                empId = Console.ReadLine();
                                Console.WriteLine("\n " + usingstoredprocedure.DeleteEmployee(empId));
                                Console.ReadLine();
                                break;

                            }

                        case 4:
                            {
                                fnm = "";
                                empId = "";
                                usingstoredprocedure.dispData(fnm, empId);
                                break;
                            }

                        case 5:
                            {
                                Console.Write(" Enter Employee Id:");
                                empId = Console.ReadLine();
                                fnm = "";

                                usingstoredprocedure.dispData(fnm, empId);
                                break;
                            }

                        case 6:
                            {
                                Console.Write(" Enter Name:");
                                fnm = Console.ReadLine();
                                empId = "";
                                usingstoredprocedure.dispData(fnm, empId);
                                break;
                            }
                    }
                }
                if (i == 7)
                {
                    Console.Write("\n You are existing!");
                    break;
                }

            }
            Console.ReadLine();
        
Conclusion

Its easy to work with Stored Procedure.



If you like this article, subscribe to our RSS Feed. You can also subscribe via email to our Interview Questions, Codes and Forums section.

Found interesting? Add this to:

| More



Please Sign In to vote for this post.

 
Latest post(s) from G_arora

Latest Articles

About Gaurav Arora

Experience:7 year(s)
Home page:http://www.mynangal.com
Member since:Monday, September 07, 2009
Level:Starter
Status: [Member]
Biography:MCA, M.Phill(Comp.Sc.),MCP, MCTS, Sr. Software Engineer.
 Response(s)
Posted by: Raja | Posted on: 09 Sep 2009 11:45:26 AM

Hi Gaurav,

I liked your other article but this article is really tough to understand. Most of this article has code snippets and I couldn't understand how this will work for stored procedure like where usingstoredprocedure.InsertEmployee method?

Could you please explain this?

Thanks

Posted by: G_arora | Posted on: 10 Sep 2009 04:15:29 AM

Hello Raja,

Thanks for your appreciation. Need to upload attachment and full code. I will update the article with description within couple of days.

Regards,
Gaurav

Submit Article

About Us | The Team | Advertise | Contact Us | Testimonials | Privacy Policy | Terms of Use | Link Exchange | Members | Go Top
General Notice: If you found plagiarised (copied) contents on this page, please let us know the original source along with your correct email id (to communicate) for further action.
Copyright © DotNetFunda.Com. All Rights Reserved. Copying or mimicking the site design and layout is prohibited. Logos, company names used here if any are only for reference purposes and they may be respective owner's right or trademarks. | 9/3/2010 3:48:14 AM