Stored Procedure
-
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();
-
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();
This is the code that creates the stored procedure
CREATE PROCEDURE DeleteUser
@userId int
AS
DELETE FROM LoginInfo WHERE uid = @UserId;
GOHere 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
-
This is the code that creates the stored procedure
CREATE PROCEDURE DeleteUser
@userId int
AS
DELETE FROM LoginInfo WHERE uid = @UserId;
GOHere 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