I have Designing as follows
Employee ID: Dropdownlist
Employee Name: textbox1
Date of birth textbox2
Age textbox3
Address textbox4
Area textbox5
Mobile No textbox6
for that how to save the record using strore procdedure please help me and send the code.
Thanks,
Rao.
Akkiraju IvaturiRank #474 · 5.2K pointsPosted Aug 27, 2012, 10:32 PM EDT
Create Procedure SaveEmployee
@EmployeeID Int,
@EmployeeName Varchar(50),
@DOB DateTime,
@Age int,
@Address Varchar(50),
@Area Varchar(50),
@Mobile Varchar(50)
AS
BEGIN
INSERT INTO TABLE1 VALUES( @EmployeeID , @EmployeeName , @DOB ... All the parameters as comma seperated)
END
If EmployeeID is Identity column, then remove the parameter @EmployeeID
SqlConnection conn = null; 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("SaveEmployee ", 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("@EmployeeID", dropdownlist.selectedvalue)); cmd.Parameters.Add(new SqlParameter("@EmployeeName", TextBox1.Text)); cmd.Parameters.Add(new SqlParameter("@DOB", TextBox2.Text));// execute the command
cmd.ExecuteNonQuery();