This is my payment.aspx.cs file
public partial class Categories_Payment : System.Web.UI.Page
{
DataTable dt;
SignIn sgn = new SignIn();
UserADO ado = new UserADO();
Utility utils = new Utility();
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
txtcurrentdate.Text = DateTime.Now.ToShortDateString();
txtcurrentdate.Enabled = false;
dt = new DataTable();
dt = (DataTable)Session["addtocart"];
GridView1.DataSource = dt;
GridView1.DataBind();
Session["addtocart"] = dt;
Txtdate.Enabled = false;
DropDownList1.Items.Insert(0, "--Select--");
DropDownList1.Items.Insert(1, "Master Card");
DropDownList1.Items.Insert(2, "Credit Card");
DropDownList1.Items.Insert(3, "Debit Card");
}
}
protected void Calendar1_SelectionChanged(object sender, EventArgs e)
{
if (Calendar1.SelectedDate > DateTime.Now)
{
Txtdate.Enabled = true;
Txtdate.Text = Calendar1.SelectedDate.ToLongDateString();
}
else
{
Txtdate.Text = "";
}
}
protected void Calendar1_DayRender(object sender, DayRenderEventArgs e)
{
if (e.Day.Date < DateTime.Now.Date)
{
e.Cell.Enabled = false;
e.Cell.BackColor = Color.White;
}
}
protected void Btn_checkout_Click(object sender, EventArgs e)
{
dt = new DataTable();
dt = (DataTable)Session["addtocart"];
string str = Session["UID"].ToString();
if (Txtcardnumber.Text.Length == 15)
{
lblMessage.Text = "<font color="red">Please enter your 16 digit card number.</font>";
return;
}
if (Txtpwd.Text.Length == 3)
{
lblMessage.Text = "<font color="red">Please enter 4 digit Password.</font>";
return;
}
string dates;
dates = txtcurrentdate.Text;
string QueryOrder = "insert into order_detail values ('" + str + "','" + dates + "') select scope_identity()";
string oid = ado.ExecuteScalerByQuery(QueryOrder);
string dp;
dp = Txtdate.Text;
string QueryPayment = "insert into paymentdetail values('" + str + "','" + oid + "','" + DropDownList1.SelectedValue + "','" + Txtcardnumber.Text + "','" + dp + "')";
ado.InsertUpdateByQuery(QueryPayment);
Session["billnum"] = oid.ToString();
Session["paymentmode"] = DropDownList1.SelectedItem.Text;
Session["cardnumber"] = Txtcardnumber.Text;
Session["xpirydate"] = Txtdate.Text;
Session["currentdate"] = txtcurrentdate.Text;
string ODetail = "";
foreach (DataRow dr in dt.Rows)
{
ODetail = "insert into oderdetail values('" + oid + "','" + dr["Tilte"].ToString() + "','" + Convert.ToInt32(dr["Qty"]) + "','" + Convert.ToDouble(dr["total"]) + "')";
ado.InsertUpdateByQuery(ODetail);
}
Response.Redirect("billgeneration.aspx");
}
}
This error occurs when i run
Server Error in '/ebook1' Application.
Conversion failed when converting date and/or time from character string.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Data.SqlClient.SqlException: Conversion failed when converting date and/or time from character string.
Source Error:
Line 148: _command.CommandType = CommandType.Text;
Line 149: _command.CommandText = strQry;
Line 150: int i = _command.ExecuteNonQuery();
Line 151: CloseConnection();
Line 152: return i;
Source File: g:\ebook1\App_Code\DL\UserADO.cs Line: 150