TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
ErPradip Kalsariya
NA
3
1k
String was not recognized as a valid DateTime.
Mar 9 2017 12:05 AM
protected void btnrenew_Click(object sender, EventArgs e)
{
int P_Id = Convert.ToInt32(((Button)sender).CommandArgument.ToString());
SqlCommand cmd = new SqlCommand("Select Renew, Term From Plans where P_Id= '" + P_Id + "'", con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
da.Fill(dt);
int RenewDate = Convert.ToDateTime(dt.Rows[0]["Renew"].ToString()).Day;
int RenewMonth = Convert.ToDateTime(dt.Rows[0]["Renew"].ToString()).Month;
int RenewYear = Convert.ToDateTime(dt.Rows[0]["Renew"].ToString()).Year;
int Term = Convert.ToInt32(dt.Rows[0]["Term"].ToString());
int TotalMonth = RenewMonth + Term;
if (TotalMonth <= 12)
{
string NextRenewDate = Convert.ToString(RenewDate.ToString("00") + "-" + TotalMonth.ToString("00") + "-" + RenewYear.ToString("00"));
SqlCommand cmd1 = new SqlCommand("Update Plans Set Renew=@Renew Where P_Id= '" + P_Id + "' ", con);
cmd1.Parameters.AddWithValue("@Renew", Convert.ToDateTime(NextRenewDate).ToString("yyyy/dd/MM"));
con.Open();
cmd1.ExecuteNonQuery();
con.Close();
ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('Your Policy RenewDate is Updated Successfully')", true);
displaydetail();
}
else if (TotalMonth > 24)
{
int NextRenewYear = RenewYear + 2;
int TotalMonth1 = (RenewMonth + Term) % 12;
string NextRenewDate1 = Convert.ToString(RenewDate.ToString("00") + "-" + TotalMonth1.ToString("00") + "-" + NextRenewYear.ToString("00"));
SqlCommand cmd1 = new SqlCommand("Update Plans Set Renew=@Renew Where P_Id = '" + P_Id + "' ", con);
cmd1.Parameters.AddWithValue("@Renew", Convert.ToDateTime(NextRenewDate1).ToString("yyyy/dd/MM"));
con.Open();
cmd1.ExecuteNonQuery();
con.Close();
ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('Your Policy RenewDate is Updated Successfully')", true);
displaydetail();
}
else if (TotalMonth > 12)
{
int NextRenewYear = RenewYear + 1;
int TotalMonth1 = (RenewMonth + Term) % 12;
string NextRenewDate1 = Convert.ToString(RenewDate.ToString("00") + "-" + TotalMonth1.ToString("00") + "-" + NextRenewYear.ToString("00"));
SqlCommand cmd1 = new SqlCommand("Update Plans Set Renew=@Renew Where P_Id = '" + P_Id + "' ", con);
cmd1.Parameters.AddWithValue("@Renew", Convert.ToDateTime(NextRenewDate1).Date);
con.Open();
cmd1.ExecuteNonQuery();
con.Close();
ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('Your Policy RenewDate is Updated Successfully')", true);
displaydetail();
}
else
{
}
}
Reply
Answers (
3
)
How to convert a word file(docx) to pdf using asp.net c#
Add a layer of caching for getdata calls