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. Database & SysAdmin
  3. Database
  4. Stored Procedure

Stored Procedure

Scheduled Pinned Locked Moved Database
databasecsharpsql-serversysadmintutorial
3 Posts 2 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.
  • S Offline
    S Offline
    simworld
    wrote on last edited by
    #1

    I need the syntax of using Stored Procedure in several cases Using C# code. and also how to create table using stored procedure in SQL server I perform below systax in my project but I want to replace them using Stored procedure in C#. DELETE SqlCommand cmd=new SqlCommand("delete from logininfo where uid='"+user_id.Text+"'",con); cmd.ExecuteNonQuery(); UPDATE SqlCommand cmd2=new SqlCommand("update logininfo set pwd ='"+ newpwd.Text) +"' where uid='"+user1+"'",con); cmd2.ExecuteNonQuery(); SELECT SqlCommand cmd=new SqlCommand("select b from logininfo where uid='"+user+"'",con); INSERT SqlCommand cmd=new SqlCommand("insert into vendor_master values('"+ name.Text +"')",con); cmd.ExecuteNonQuery();

    C 1 Reply Last reply
    0
    • S simworld

      I need the syntax of using Stored Procedure in several cases Using C# code. and also how to create table using stored procedure in SQL server I perform below systax in my project but I want to replace them using Stored procedure in C#. DELETE SqlCommand cmd=new SqlCommand("delete from logininfo where uid='"+user_id.Text+"'",con); cmd.ExecuteNonQuery(); UPDATE SqlCommand cmd2=new SqlCommand("update logininfo set pwd ='"+ newpwd.Text) +"' where uid='"+user1+"'",con); cmd2.ExecuteNonQuery(); SELECT SqlCommand cmd=new SqlCommand("select b from logininfo where uid='"+user+"'",con); INSERT SqlCommand cmd=new SqlCommand("insert into vendor_master values('"+ name.Text +"')",con); cmd.ExecuteNonQuery();

      C Offline
      C Offline
      Colin Angus Mackay
      wrote on last edited by
      #2

      This is the code that creates the stored procedure

      CREATE PROCEDURE DeleteUser
      @userId int
      AS
      DELETE FROM LoginInfo WHERE uid = @UserId;
      GO

      Here is the snipped that calls the stored procedure from C#

      int userId = int.Parse(user_id.Text);
      SqlCommand cmd = new SqlCommand("DeleteUser");
      cmd.CommandType = CommandType.StoredProcedure;
      cmd.Connection = myConnection;
      cmd.Parameters.AddWithValue("@UserId", userId);
      cmd.ExecuteNonQuery();

      You should, hopefully, be able to figure the rest out from this example.

      Upcoming FREE developer events: * Developer Day Scotland Recent blog posts: * Follow up on hiring a software developer * The Value of Smaller Methods My website | blog

      S 1 Reply Last reply
      0
      • C Colin Angus Mackay

        This is the code that creates the stored procedure

        CREATE PROCEDURE DeleteUser
        @userId int
        AS
        DELETE FROM LoginInfo WHERE uid = @UserId;
        GO

        Here is the snipped that calls the stored procedure from C#

        int userId = int.Parse(user_id.Text);
        SqlCommand cmd = new SqlCommand("DeleteUser");
        cmd.CommandType = CommandType.StoredProcedure;
        cmd.Connection = myConnection;
        cmd.Parameters.AddWithValue("@UserId", userId);
        cmd.ExecuteNonQuery();

        You should, hopefully, be able to figure the rest out from this example.

        Upcoming FREE developer events: * Developer Day Scotland Recent blog posts: * Follow up on hiring a software developer * The Value of Smaller Methods My website | blog

        S Offline
        S Offline
        simworld
        wrote on last edited by
        #3

        Yes ,I think i can do the rest. Thank u very much.

        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