Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. How to access stored procedure

How to access stored procedure

Scheduled Pinned Locked Moved C#
csharpdatabasetutorialcareer
6 Posts 6 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • F Offline
    F Offline
    fancyfree83
    wrote on last edited by
    #1

    I have created stored procedure for calculating salary.how will i access that procedure using c#.NET

    vinoth

    W T N J A 5 Replies Last reply
    0
    • F fancyfree83

      I have created stored procedure for calculating salary.how will i access that procedure using c#.NET

      vinoth

      W Offline
      W Offline
      Wendelius
      wrote on last edited by
      #2

      You use SqlCommand Class[^]

      The need to optimize rises from a bad design

      1 Reply Last reply
      0
      • F fancyfree83

        I have created stored procedure for calculating salary.how will i access that procedure using c#.NET

        vinoth

        T Offline
        T Offline
        TALHAKOSEN
        wrote on last edited by
        #3

        Look at that, it can give you an idea ) conn = new SqlConnection("Server=(local);DataBase=Northwind;Integrated Security=SSPI"); conn.Open(); // 1. create a command object identifying // the stored procedure SqlCommand cmd = new SqlCommand( "CustOrderHist", conn); // 2. set the command object so it knows // to execute a stored procedure cmd.CommandType = CommandType.StoredProcedure; // 3. add parameter to command, which // will be passed to the stored procedure cmd.Parameters.Add( new SqlParameter("@CustomerID", custId));

        thanks for everything i have...

        1 Reply Last reply
        0
        • F fancyfree83

          I have created stored procedure for calculating salary.how will i access that procedure using c#.NET

          vinoth

          N Offline
          N Offline
          Nouman Bhatti
          wrote on last edited by
          #4

          if you are using SQL then you need 1. import the system.data.sqlclient namespace 2. then create a object of sqlconnection with appropriate parameters 3. then either create a objects of sqlcommand and sqldatareader and in commad specify the storedprocedure name or you can also create a object of sqldataadaptar and sqldataset and in sqldataadaptar you can set your stored procedure name. if u r working on anyother db than import the namespace and create objects accordingly

          1 Reply Last reply
          0
          • F fancyfree83

            I have created stored procedure for calculating salary.how will i access that procedure using c#.NET

            vinoth

            J Offline
            J Offline
            Jaffer Mumtaz
            wrote on last edited by
            #5

            Hi, Visit http://support.microsoft.com/kb/310070[^] Try to learn to use google for such queries

            1 Reply Last reply
            0
            • F fancyfree83

              I have created stored procedure for calculating salary.how will i access that procedure using c#.NET

              vinoth

              A Offline
              A Offline
              Ashwin Shetty
              wrote on last edited by
              #6

              if you r using SQL please check the below code string strSqlConnectionstring = "sqlserver details with provider"; System.Data.SqlClient.SqlConnection _ObjSQLCon = new System.Data.SqlClient.SqlConnection(strSqlConnectionstring.ToString()); System.Data.SqlClient.SqlCommand _ObjSqlCom = new System.Data.SqlClient.SqlCommand(); try { _ObjSQLCon.Open(); _ObjSqlCom.Connection = _ObjSQLCon; // your store procedure name _ObjSqlCom.CommandText = "Your Store procedure name"; _ObjSqlCom.CommandType = System.Data.CommandType.StoredProcedure; // you can add parameter as per your requirement // parameter name & datatype should be as per you have mentioned in your procedure // set the direction of your parameter // you need to add output parameter in the same way but direction out be output _ObjSqlCom.Parameters.Add("your parameter name", System.Data.SqlDbType.Char, 50).Direction = System.Data.ParameterDirection.Input; _ObjSqlCom.Parameters.Add("your output parameter name", System.Data.SqlDbType.Char, 50).Direction = System.Data.ParameterDirection.Output; _ObjSqlCom.Parameters[0].Value = "your parameter value"; _ObjSqlCom.ExecuteNonQuery(); // to get the output value you can use either array location of that parameter or the parameter name // if you are confused then just right click on _ObjSqlCom and view it in immediate window after you have executed _ObjSqlCom.ExecuteNonQuery(); } catch { } finally { strSqlConnectionstring = string.Empty; if (_ObjSqlCom != null) { _ObjSqlCom.Dispose(); _ObjSqlCom = null; } if (_ObjSQLCon != null) { if (_ObjSQLCon.State != System.Data.ConnectionState.Closed) { _ObjSQLCon.Close(); } _ObjSQLCon.Dispose(); _ObjSQLCon = null; } } if you further douts feel free to email me at ashwin@omtechsolutions.com :)

              Ashwin Shetty. Mumbai. India

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups