how to insert data in table using asp c#
CREATE TABLE [dbo].[ts2] (
[Id] INT IDENTITY (1, 1) NOT NULL,
[Dept] VARCHAR (50) NULL,
[wrk_nm] VARCHAR (5000) NULL,
[fts_no] NCHAR (10) NULL,
[prced_by_dept_date] NCHAR (10) NULL,
[estmt_cst] NCHAR (100) NULL,
[prpsl_sts] VARCHAR (5000) NULL,
[prsnt_lctn] NCHAR (10) NULL,
[in_prss_sinc] VARCHAR (50) NULL,
[updated_on] DATETIME DEFAULT (getdate()) NOT NULL,
PRIMARY KEY CLUSTERED ([Id] ASC)
);
CREATE procedure TS1
(
@Dept varchar ,
@wrk_nm varchar,
@fts_no nchar ,
@prced_by_dept_date nchar,
@estmt_cst nchar,
@prpsl_sts varchar,
@prsnt_lctn nchar,
@in_prss_sinc varchar,
@updated_on date ,
@Event varchar(10)
)
AS
BEGIN
IF(@Event='Select')
BEGIN
SELECT * FROM TS ORDER BY Id ASC;
END
ELSE IF(@Event='Add')
BEGIN
Insert into TS(
Dept ,
wrk_nm ,
fts_no ,
prced_by_dept_date ,
estmt_cst,
prpsl_sts,
prsnt_lctn ,
in_prss_sinc ,
updated_on
)
values
(
@Dept ,
@wrk_nm ,
@fts_no ,
@prced_by_dept_date ,
@estmt_cst ,
@prpsl_sts ,
@prsnt_lctn ,
@in_prss_sinc ,
@updated_on
)
END
END
protected void Btnsave_Click(object sender, EventArgs e)
{
try
{
CreateConnection();
OpenConnection();
_sqlCommand.CommandText = "TS1";
_sqlCommand.CommandType = CommandType.StoredProcedure;
_sqlCommand.Parameters.AddWithValue("@Event", "Add");
_sqlCommand.Parameters.AddWithValue("@Dept ", TextBox2.Text.ToString());
_sqlCommand.Parameters.AddWithValue("@wrk_nm ", TextBox3.Text.ToString());
_sqlCommand.Parameters.AddWithValue("@fts_no", TextBox4.Text.ToString());
_sqlCommand.Parameters.AddWithValue("@estmt_cst ", TextBox5.Text.ToString());
_sqlCommand.Parameters.AddWithValue("@prpsl_sts ", TextBox13.Text.ToString());
_sqlCommand.Parameters.AddWithValue("@prsnt_lctn ", TextBox7.Text.ToString());
_sqlCommand.Parameters.AddWithValue("@prced_by_dept_date", datepicker.Text.ToString());
_sqlCommand.Parameters.AddWithValue("@in_prss_sinc ", TextBox13.Text.ToString());
}
catch (Exception ex)
{
Response.Write("<script language='javascript'>window.alert('Record has been already exits. !!!!!!!!!!!');window.location='Index.aspx';</script>");
}
finally
{
CloseConnection();
DisposeConnection();
}
}