how to update a record or value in sqlserver 2005 using asp.net.
my problem is if iam having a number 20 in my database, now iwant to subtract 5 and update that record into 15.
my DATABASE Leaverecord
Id-------LeaveRemaining
1-------------20
2-------------18
3-------------18
the code which i developed was not correct actually, so please help me in ExecuteUpdate() method. i want to know how to pass the value into that method
public partial class Applying : System.Web.UI.Page
{
String connectionString = ConfigurationManager.ConnectionStrings["SQLDbconnection"].ToString();
SqlConnection con;
public Applying()
{
con = new SqlConnection(connectionString);
}
protected void Page_Load(object sender, EventArgs e)
{
tbStartdate_CalendarExtender.StartDate = DateTime.Today;
tbEndDate_CalendarExtender.StartDate = DateTime.Today.AddDays(1);
}
public void btnOk_Click(object sender, EventArgs e)
{
DateTime StartDate1 = DateTime.ParseExact(tbStartdate.Text, "dd/MM/yyyy", System.Globalization.CultureInfo.InvariantCulture);
DateTime EndDate1 = DateTime.ParseExact(tbEnddate.Text, "dd/MM/yyyy", System.Globalization.CultureInfo.InvariantCulture);
TimeSpan diffResult = EndDate1.Subtract(StartDate1);
int NoOfDays = Convert.ToInt32(diffResult.Days);
ExecuteUpdate(NoOfDays);
}
}
private void ExecuteUpdate() // help me in this code
{
con.Open();
SqlCommand cmd1 = new SqlCommand();
string sql_update="UPDATE LeaveRecord SET LeavesRemaining WHERE Id=' "+tbID.Text+" ' ";
cmd1.CommandType = CommandType.Text;
cmd1.ExecuteNonQuery();
con.Close();
}