Click here to Skip to main content
15,888,324 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
i have a table with fields as empid int,emp_name varchar(50),emp_phno char(10),emp_add varchar(75)
i have to create a stored procedure using insert,update,delete operations....thanks in advance
Posted
Comments
sahabiswarup 27-May-13 4:01am    
have you googled it?
Maciej Los 27-May-13 4:29am    
What have you tried?
Where are you stuck?

Please visit this site.

http://www.mssqltips.com/sqlservertutorial/160/sql-server-stored-procedure/[^]

in this site you have very basic example. try this..
Have any query or doubts please let me know..
 
Share this answer
 
Comments
Maciej Los 27-May-13 4:49am    
It's fair enough.
+5!
Rambo_Raja 27-May-13 4:57am    
i want to add a row in table when i exec a stored proc...similarly delete and update table to create a stored proc my code is ..please help me ....thanks

create procedure getinsert_emp
(
@empid int,@emp_name varchar(50),@emp_Add varchar(70),@emp_phno char(10))
As
begin
if @empid = 'empid'
insert into employee_test
values (@empid ,@emp_name ,@emp_Add ,@emp_phno )
Start here: Stored Procedures (Database Engine)[^] and read all related articles:
Implementing SP[^]
Creating SP[^]
Execute SP[^]

I think it's quite enough for start ;)
 
Share this answer
 
v2
you can try this
SQL
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE StoredProcedureName 
@action varchar(10),
@empid int,
@emp_name varchar(50),
@emp_phno char(10),
@emp_add varchar(75)

AS

IF @action ='Save'
BEGIN
INSERT INTO TabelName (emp_name,emp_phno,emp_add)
VALUES (@emp_name,@emp_phno,@emp_add)
END

ELSE IF @action ='Update'
BEGIN
UPDATE TabelName SET 
emp_name = @emp_name,
emp_phno = @emp_phno,
emp_add = @emp_add
WHERE     (empid = @empid)
END

ELSE IF @action ='Delete'
BEGIN
DELETE FROM TabelName
WHERE     (empid = @empid)
End
 
Share this answer
 
Comments
Rambo_Raja 27-May-13 5:38am    
sir thnx for the great help but also want to know how to implement it using search action....also how to execute it
M.Saied 27-May-13 7:17am    
you can add sampel code under your save button like this

protected void SaveButton_Click(object sender, EventArgs e)
{
SqlConnection ConnectionName = new SqlConnection();
ConnectionName.ConnectionString = WebConfigurationManager.ConnectionStrings["ConnectionStringName"].ConnectionString;
ConnectionName.Open();

SqlCommand comm = new SqlCommand();
comm.Connection = ConnectionName;
comm.Parameters.Clear();
comm.CommandType = CommandType.StoredProcedure;
comm.CommandText = "StoredProcedureName";

comm.Parameters.AddWithValue("action", "actionName");
comm.Parameters.AddWithValue("emp_name", TextBox1.Text);
comm.Parameters.AddWithValue("emp_phno", TextBox2.Text);

comm.ExecuteNonQuery();
ConnectionName.Close();
ResaultLabel.Text = "Save Successfully";
}

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900