sql stored procedure
Create PROCEDURE [dbo].[AddDEmp]
(
@empName Varchar(50),
@empAge int,
@empEmail nVarchar(50),
@PhoneNo nVarchar(50)
)
AS
INSERT INTO empRecord(empName,empAge,empEmail,PhoneNo) VALUES(@empName,@empAge,@empEmail,@PhoneNo)
--------------------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
public partial class storedProcedureInsert : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
string constr = "Data Source=RLABSRV/SQLEXPRESS;Initial Catalog=employee;Integrated Security=True";
//DataTable allData = new DataTable();
SqlConnection con = new SqlConnection(constr);
try
{
SqlCommand cmd = new SqlCommand("AddDEmp", con);
cmd.CommandType = CommandType.StoredProcedure;
con.Open();
cmd.Parameters.Add("empName", SqlDbType.VarChar, 50);
cmd.Parameters["empName"].Value = TextBox1.Text;
cmd.Parameters.Add("empAge", SqlDbType.Int);
cmd.Parameters["empAge"].Value = TextBox2.Text;
cmd.Parameters.Add("empEmail", SqlDbType.NVarChar, 50);
cmd.Parameters["empEmail"].Value = TextBox3.Text;
cmd.Parameters.Add("PhoneNo", SqlDbType.NVarChar, 50);
cmd.Parameters["PhoneNo"].Value = TextBox4.Text;
cmd.ExecuteNonQuery();
con.Close();
}
catch(Exception ex)
{
con.Close();
Label2.Text = ex.Message;
}
}
}
No comments:
Post a Comment