Click here to Skip to main content
15,885,216 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
C#
try
{
  con.Open();
  SqlCommand cmd = new SqlCommand();
  SqlDataAdapter da = new SqlDataAdapter(cmd);
  cmd.CommandType = CommandType.StoredProcedure;
  cmd.CommandText = "SP_PaymentTracker";
  cmd.Parameters.AddWithValue("@Name", txtName.Text);
  cmd.Parameters.AddWithValue("@InvestmentType", txtInvestmentType.Text);
  cmd.Parameters.AddWithValue("@Amount", txtAmount.Text);
  cmd.Parameters.AddWithValue("@MonthlyPay", txtMonthlyPay.Text);
  cmd.Parameters.AddWithValue("@NumberOfMonths", txtNoOfMonths.Text);
  cmd.Parameters.AddWithValue("@StartDate", txtStartDate.Text);

  cmd.Parameters.AddWithValue("@EndDate", txtEndDate.Text);
  cmd.Parameters.AddWithValue("@Phone", txtMobile.Text);
  cmd.Parameters.AddWithValue("@Address", txtAddress.Text);
  cmd.Connection = con;

  cmd.ExecuteNonQuery();
}
catch (Exception ex)
{
  throw ex;
}
finally
{
  con.Close();
  con.Dispose();
  txtName.Text = txtInvestmentType.Text = txtAmount.Text = txtMonthlyPay.Text =
  txtNoOfMonths.Text = txtStartDate.Text = txtEndDate.Text = txtMobile.Text = txtAddress.Text = string.Empty;
}

this is my code

so please provide me the End Date Default based on Number Of Months and Start Date
Posted
Updated 18-May-15 0:18am
v2
Comments
Arun Kumar_Tech 18-May-15 6:17am    
convert txtStartDate to datetime, then follow the below code
txtStartDate.AddMonths(txtNoOfMonths)
Member 11177087 18-May-15 6:25am    
Thans #Arun Kumar_Tech

Where I placed these provided code please tell meindetail

1 solution

SQL
convert txtStartDate to datetime, then follow the below code
txtStartDate.AddMonths(txtNoOfMonths)
 
Share this answer
 
Comments
Member 11177087 18-May-15 6:42am    
I mean where the put these code

please reply me
Arun Kumar_Tech 19-May-15 0:31am    
Before insert in to database, Read the startdate and month from textbox pass it to the above code and insert the ouput as end date to database..
Member 11177087 19-May-15 6:56am    
con.Open();
SqlCommand cmd = new SqlCommand();
SqlDataAdapter da = new SqlDataAdapter(cmd);
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "SP_PaymentTracker1";
cmd.Parameters.AddWithValue("@Name", txtName.Text);
cmd.Parameters.AddWithValue("@InvestmentType", txtInvestmentType.Text);
cmd.Parameters.AddWithValue("@Amount", txtAmount.Text);
cmd.Parameters.AddWithValue("@MonthlyPay", txtMonthlyPay.Text);
cmd.Parameters.AddWithValue("@NumberOfMonths", txtNumberOfMonths.Text);
cmd.Parameters.AddWithValue("@StartDate", txtStartDate.Text);

var dateFormat = Convert.ToDateTime("@StartDate");

cmd.Parameters.AddWithValue("@EndDate", dateFormat.AddMonths(txtNumberOfMonths));

cmd.Parameters.AddWithValue("@Phone", txtPhone.Text);
cmd.Parameters.AddWithValue("@Address", txtAddress.Text);
cmd.Connection = con;


cmd.ExecuteNonQuery();


here having the error like overloaded in enddate

so please solve it....

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900