ANURADHA

ANURADHA

  • NA
  • 18
  • 5k

how to insert defalut value in table in ASP.NET C#

Jul 24 2014 4:34 AM
Dear  Friends
 
ple  help  me
 
How  to  insert   one   field   with  defalut  value  (like  yes  or  no)   in  table    in  asp.net  C#
my  coding  given bellow:
 

using System;

using System.Data;

using System.Configuration;

using System.Collections;

using System.Web;

using System.Web.Security;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Web.UI.WebControls.WebParts;

using System.Web.UI.HtmlControls;

using System.Data.SqlClient;

namespace Drop

{

public partial class AC_Complaints : System.Web.UI.Page

{

SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["conn"].ConnectionString);

DataSet ds = new DataSet();

SqlConnection con;

//Here we declare the parameter which we have to use in our application

//SqlCommand cmd = new SqlCommand();

//SqlParameter sp1 = new SqlParameter();

//SqlParameter sp2 = new SqlParameter();

//SqlParameter sp3 = new SqlParameter();

//SqlParameter sp4 = new SqlParameter();

//SqlParameter sp5 = new SqlParameter();

//SqlParameter sp6 = new SqlParameter();

//SqlParameter sp7 = new SqlParameter();

//SqlParameter sp8 = new SqlParameter();

//SqlParameter sp9 = new SqlParameter();

//SqlParameter sp10 = new SqlParameter();

//SqlParameter sp11 = new SqlParameter();

protected void Page_Load(object sender, EventArgs e)

{

txtprno.Text = Session["PRNO"].ToString();

{

conn.Open();

}

String strConnString = ConfigurationManager.ConnectionStrings["conn"].ConnectionString;

SqlConnection con = new SqlConnection(strConnString);

SqlCommand cmd = new SqlCommand();

SqlDataAdapter da = new SqlDataAdapter();

cmd.CommandType = CommandType.StoredProcedure;

cmd.CommandText = "GET_EMPDETLS";

cmd.Parameters.Add("@prno", SqlDbType.Text).Value = txtprno.Text.Trim();

 

cmd.Connection = con;

try

{

con.Open();

DataSet ds = new DataSet();

da = new SqlDataAdapter(cmd);

da.Fill(ds);

txtname.Text = ds.Tables[0].Rows[0]["H01_First_name"].ToString();

txtdesign.Text = ds.Tables[0].Rows[0]["C12_PositionCODE"].ToString();

txtDepartment.Text = ds.Tables[0].Rows[0]["C02_FUNCTION_DESC"].ToString();

txttime.Text = System.DateTime.Now.ToLongTimeString();

txtdate.Text = System.DateTime.Now.ToShortDateString();

}

catch (Exception ex)

{

throw ex;

}

finally

{

con.Close();

con.Dispose();

}

}

protected void Button1_Click(object sender, EventArgs e)

{

SqlCommand cmd = new SqlCommand("insert into AC_COMPLAINT_SYS values('" + txtprno.Text + "','" + txtname.Text + "','" + txtdesign.Text + "','" + txtDepartment.Text + "','" + txtlocation.Text + "','" + DropDownList1.Text + "','" + DropDownList2.Text + "','" + txtcomplaint.Text + "','" + txtinter.Text + "','" + txtdate.Text + "','" + txttime.Text + "','" + this is  defalut value + "')", conn);

cmd.ExecuteNonQuery();

conn.Close();

lblMessage.Visible =true;

lblMessage.Text = "Your data inserted successfully";

//txtCity.Text = "";

//txtFName.Text = "";

//txtLName.Text = "";

}

//AC_COMPLAINT_INSERT_INTRA ="INSERT INTO AC_Complaint_SYS (PRNO, NAME, DESGN ,DEPT_NAME, LOCATION, OPERATING_SYSTEM, COMPLAINT_DETAILS, COMPLAINT_DETAILS, INTERCOM_NO,ENTRY_DATE,ENTRY_TIME)" VALUES (@PRNO, @NAME, @DESGN ,@DEPT_NAME, @LOCATION, @OPERATING_SYSTEM, @COMPLAINT_DETAILS, @COMPLAINT_DETAILS, @INTERCOM_NO,@ENTRY_DATE,@ENTRY_TIME)", Con);

// String strConnString = ConfigurationManager.ConnectionStrings["conn"].ConnectionString;

// SqlCommand cmd = new SqlCommand();

// SqlDataAdapter da = new SqlDataAdapter();

// cmd.CommandType = CommandType.StoredProcedure;

// cmd.CommandText = "AC_COMPLAINT_INSERT_INTRA";

 

// cmd.Parameters.Add("@PRNO", SqlDbType.VarChar).Value = txtprno.Text.Trim();

// cmd.Parameters.Add("@NAME", SqlDbType.VarChar).Value = txtname.Text.Trim();

// cmd.Parameters.Add("@DESGN", SqlDbType.VarChar).Value = txtdesign.Text.Trim();

// cmd.Parameters.Add("@DEPT_NAME", SqlDbType.VarChar).Value = txtDepartment.Text.Trim();

// cmd.Parameters.Add("@LOCATION", SqlDbType.VarChar).Value = txtlocation.Text.Trim();

// cmd.Parameters.Add("@OPERATING_SYSTEM", SqlDbType.VarChar).Value = DropDownList1.Text.Trim();

// cmd.Parameters.Add("@COMPLAINT_TYPE", SqlDbType.VarChar).Value = DropDownList2.Text.Trim();

// cmd.Parameters.Add("@COMPLAINT_DETAILS", SqlDbType.VarChar).Value = txtcomplaint.Text.Trim();

// cmd.Parameters.Add("@INTERCOM_NO", SqlDbType.VarChar).Value = txtinter.Text.Trim();

// cmd.Parameters.Add("@ENTRY_DATE", SqlDbType.VarChar).Value = txtdate.Text.Trim();

// cmd.Parameters.Add("@ENTRY_TIME", SqlDbType.VarChar).Value = txttime.Text.Trim();

// cmd.Connection = con;

// try

// {

// con.Open();

// cmd.ExecuteNonQuery();

// lblMessage.Text = "Student inserted sucessfully";

// }

// catch //(Exception ex)

// {

// //throw ex;

// lblMessage.Text = "Student NOT inserted";

// }

// //finally

// //{

// // con.Close();

// // con.Dispose();

// //}

}

}


Answers (6)