hi Indradeo,
Kindly refer below modified code.
Namespaces
using System.Data;
using System.Data.SqlClient;
using System.Data.SqlTypes;
Code
protected void Page_Load(object sender, EventArgs e)
{
Label1.Visible = false;
}
protected void Btnsave_Click(object sender, EventArgs e)
{
string sqlStmt;
string conString;
SqlConnection cn = null;
SqlCommand cmd = null;
SqlDateTime sqldatenull;
try
{
sqlStmt = "insert into ts2 (Dept,wrk_nm,fts_no,prced_by_dept_date,estmt_cst,prpsl_sts,prsnt_lctn,in_prss_sinc) Values (@Dept,@wrk_nm,@fts_no,@prced_by_dept_date,@estmt_cst,@prpsl_sts,@prsnt_lctn,@in_prss_sinc)";
conString = @"Data Source=.;Initial Catalog=Test;uid=sa;pwd=pass@123;";
cn = new SqlConnection(conString);
cmd = new SqlCommand(sqlStmt, cn);
cmd.Parameters.Add(new SqlParameter("@Dept", SqlDbType.NVarChar, 11));
cmd.Parameters.Add(new SqlParameter("@wrk_nm", SqlDbType.NVarChar, 500));
cmd.Parameters.Add(new SqlParameter("@fts_no", SqlDbType.NVarChar, 10));
cmd.Parameters.Add(new SqlParameter("@prced_by_dept_date", SqlDbType.DateTime));
cmd.Parameters.Add(new SqlParameter("@estmt_cst", SqlDbType.NVarChar, 10));
cmd.Parameters.Add(new SqlParameter("@prpsl_sts", SqlDbType.NVarChar, 500));
cmd.Parameters.Add(new SqlParameter("@prsnt_lctn", SqlDbType.NVarChar, 10));
cmd.Parameters.Add(new SqlParameter("@in_prss_sinc", SqlDbType.DateTime));
sqldatenull = SqlDateTime.Null;
cmd.Parameters["@Dept"].Value = TextBox2.Text;
cmd.Parameters["@wrk_nm"].Value = TextBox3.Text;
cmd.Parameters["@fts_no"].Value = TextBox4.Text;
cmd.Parameters["@estmt_cst"].Value = TextBox6.Text;
cmd.Parameters["@prpsl_sts"].Value = TextBox13.Text;
cmd.Parameters["@prsnt_lctn"].Value = TextBox7.Text;
cmd.Parameters["@in_prss_sinc"].Value = TextBox5.Text;
if (datepicker.Text == "")
{
cmd.Parameters["@prced_by_dept_date"].Value = sqldatenull;
}
else
{
cmd.Parameters["@prced_by_dept_date"].Value = DateTime.Parse(datepicker.Text);
}
if (TextBox5.Text == "")
{
cmd.Parameters["@in_prss_sinc"].Value = sqldatenull;
}
else
{
cmd.Parameters["@in_prss_sinc"].Value = DateTime.Parse(TextBox5.Text);
}
cn.Open();
cmd.ExecuteNonQuery();
Label1.Text = "Record Inserted Succesfully";
}
catch (Exception ex)
{
Label1.Text = ex.Message;
}
finally
{
cn.Close();
}
}
protected void Button1_Click(object sender, EventArgs e)
{
datepicker.Text = "";
TextBox2.Text = "";
TextBox3.Text = "";
TextBox4.Text = "";
TextBox5.Text = "";
TextBox6.Text = "";
TextBox7.Text = "";
TextBox13.Text = "";
}
protected void Back_Click(object sender, EventArgs e)
{
Response.Redirect("~/Index.aspx");
}