i wrote the code for the above operations to be performed is below
public partial class insertupdatedeletepractice : System.Web.UI.Page
{
string cs = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
SqlConnection con; SqlCommand cmd; SqlDataSource ds; SqlParameter P1;
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
try
{
SqlConnection con = new SqlConnection(cs);
SqlCommand cmd = new SqlCommand("InsertRecord", con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@PEmployeeId", TextBox1.Text);
cmd.Parameters.AddWithValue("@PEmployeeName", TextBox2.Text);
cmd.Parameters.AddWithValue("@PEmployeeDesignation", TextBox3.Text);
cmd.Parameters.AddWithValue("@PEmployeeDOJ", TextBox4.Text);
cmd.Parameters.AddWithValue("@PEmployeeSalary", TextBox5.Text);
cmd.Parameters.AddWithValue("@PEmployeeDepartmentno", TextBox6.Text);
con.Open();
int i = cmd.ExecuteNonQuery();
con.Close();
Console.WriteLine("Data Inserted");
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
protected void btnupdate_Click(object sender, EventArgs e)
{
try
{
SqlConnection con = new SqlConnection(cs);
SqlCommand cmd = new SqlCommand("UpdateRecord", con);
cmd.CommandType = CommandType.StoredProcedure;
P1 = new SqlParameter("@PEmployeeId", SqlDbType.Int);
P1.Value = Convert.ToInt32(TextBox1.Text);
cmd.Parameters.Add(P1);
P1 = new SqlParameter("@PEmployeeDesignation", SqlDbType.VarChar);
P1.Value = Convert.ToInt32(TextBox2.Text);
cmd.Parameters.Add(P1);
P1 = new SqlParameter("@PEmployeeDOJ", SqlDbType.Date);
P1.Value = Convert.ToInt32(TextBox3.Text);
cmd.Parameters.Add(P1);
P1 = new SqlParameter("@PEmployeeDesignation", SqlDbType.VarChar);
P1.Value = Convert.ToInt32(TextBox4.Text);
cmd.Parameters.Add(P1);
P1 = new SqlParameter("@PEmployeeSalary", SqlDbType.Money);
P1.Value = Convert.ToInt32(TextBox5.Text);
cmd.Parameters.Add(P1);
P1 = new SqlParameter("@PEmployeeDepartmentno", SqlDbType.Int);
P1.Value = Convert.ToInt32(TextBox6.Text);
cmd.Parameters.Add(P1);
con.Open();
int i = cmd.ExecuteNonQuery();
con.Close();
Console.WriteLine("Data Updated");
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
protected void btnfind_Click(object sender, EventArgs e)
{
try
{
SqlConnection con = new SqlConnection(cs);
SqlCommand cmd = new SqlCommand("GetData", con);
cmd.CommandType = CommandType.StoredProcedure;
P1 = new SqlParameter("@PEmployeeId",SqlDbType.Int);
P1.Value = Convert.ToInt32(TextBox1.Text);
cmd.Parameters.Add(P1);
P1 = new SqlParameter("@PEmployeeName", SqlDbType.VarChar);
P1.Direction = ParameterDirection.Output;
cmd.Parameters.Add(P1);
P1 = new SqlParameter("@PEmployeeDesignation", SqlDbType.VarChar);
P1.Direction = ParameterDirection.Output;
cmd.Parameters.Add(P1);
P1 = new SqlParameter("@PEmployeeDOJ", SqlDbType.Date);
P1.Direction = ParameterDirection.Output;
cmd.Parameters.Add(P1);
P1 = new SqlParameter("@PEmployeeSalary", SqlDbType.Money);
P1.Direction = ParameterDirection.Output;
cmd.Parameters.Add(P1);
P1 = new SqlParameter("@PEmployeeDepartmentno", SqlDbType.Int);
P1.Direction = ParameterDirection.Output;
cmd.Parameters.Add(P1);
con.Open();
cmd.ExecuteNonQuery();
con.Close();
TextBox2.Text = cmd.Parameters["@PEmployeeName"].ToString();
TextBox3.Text = cmd.Parameters["@PEmployeeDesignation"].ToString();
TextBox4.Text = cmd.Parameters["@PEmployeeDOJ"].ToString();
TextBox5.Text = cmd.Parameters["@PEmployeeSalary"].ToString();
TextBox6.Text = cmd.Parameters["@PEmployeeDepartmentno"].ToString();
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
protected void btndelete_Click(object sender, EventArgs e)
{
try
{
cmd = new SqlCommand("DeleteRecord", con);
cmd.CommandType = CommandType.StoredProcedure;
P1 = new SqlParameter("@PEmployeeId", SqlDbType.Int);
cmd.Parameters.AddWithValue("@PEmployeeId", TextBox1.Text);
P1.Value = Convert.ToInt32(TextBox1.Text);
cmd.Parameters.Add(P1);
con.Open();
cmd.ExecuteNonQuery();
con.Close();
Console.WriteLine("Record Deleted");
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
}
the problem is inserting is working very fine but remaining operations are not working at all why? please tell me and correct me thanks in advance