Hello Admin / Friends ,
i am working on website where i am getting error when try to insert data into database
from my asp.net website
The Error says that :
" System.Data.SqlClient.SqlException :
The conversion of a varchar data type to a datetime data type resulted in
an out-of-range value."
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
public partial class ProductDetails : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
try
{
if (Session["UserName"] != null)
{
}
else
{
Response.Redirect("Home.aspx");
}
}
catch (Exception ex)
{
Response.Write(Convert.ToString(ex.Message));
}
finally
{
}
}
public void databind()
{
try
{
String Query1 = "Select * From Item_New";
DataSet DataSet1;
DataSet1 = new DataSet();
DataSet1 = OnlinePizzaOrder.Connection.Select_Query(Query1);
}
catch (Exception ex)
{
Response.Write(Convert.ToString(ex.Message));
}
finally
{
}
}
protected void Button1_Click(object sender, EventArgs e)
{
try
{
String UserId, Qty;
String ItemSmall, ItemMedium, ItemLarge;
String RadioSmallCheck="", RadioMediumCheck="", RadioLargeCheck="";
int ProductID;
Double Total=0;
UserId = Session["UserId"].ToString();
ProductID = int.Parse(Request.QueryString["ProductID"]);
Qty = ((TextBox)DataList2.Controls[0].FindControl("TxtQuantity")).Text;
ItemSmall = "";
ItemMedium = "";
ItemLarge = "";
Table TableNew1 = new Table();
foreach(DataListItem li in DataList2.Items)
{
TableNew1 = (Table)li.FindControl("Table1");
}
RadioButton RdoSmall = new RadioButton();
RadioButton RdoMedium = new RadioButton();
RadioButton RdoLarge = new RadioButton();
foreach (TableRow TableRow1 in TableNew1.Rows)
{
foreach (TableCell TableCell1 in TableRow1.Cells)
{
foreach (Control Control1 in TableCell1.Controls)
{
if (Control1.ID == "LblSmall")
{
Label L1 = (Label)Control1;
ItemSmall = L1.Text;
}
else if (Control1.ID == "LblMedium")
{
Label L2 = (Label)Control1;
ItemMedium = L2.Text;
}
else if (Control1.ID == "LblLarge")
{
Label L3 = (Label)Control1;
ItemLarge = L3.Text;
}
}
}
}
foreach (TableRow TableRow1 in TableNew1.Rows)
{
foreach (TableCell TableCell1 in TableRow1.Cells)
{
foreach (Control Control1 in TableCell1.Controls)
{
if (Control1.ID == "RadioButton1")
{
RdoSmall = (RadioButton)Control1;
if (RdoSmall.Checked == true)
{
Total = Convert.ToDouble(Qty) * Convert.ToDouble(ItemSmall);
ItemMedium = "";
ItemLarge = "";
RadioSmallCheck = "YES";
}
else
{
RadioSmallCheck = "NO";
}
}
else if (Control1.ID == "RadioButton2")
{
RdoMedium = (RadioButton)Control1;
if (RdoMedium.Checked == true)
{
Total = Convert.ToDouble(Qty) * Convert.ToDouble(ItemMedium);
ItemSmall = "";
ItemLarge = "";
RadioMediumCheck = "YES";
}
else
{
RadioMediumCheck = "NO";
}
}
else if (Control1.ID == "RadioButton3")
{
RdoLarge = (RadioButton)Control1;
if (RdoLarge.Checked == true)
{
Total = Convert.ToDouble(Qty) * Convert.ToDouble(ItemLarge);
ItemSmall = "";
ItemMedium = "";
RadioLargeCheck = "YES";
}
else
{
RadioLargeCheck = "NO";
}
}
}
}
}
if (RadioSmallCheck == "NO" && RadioMediumCheck == "NO" && RadioLargeCheck == "NO")
{
Page.ClientScript.RegisterClientScriptBlock(typeof(Page), "Alert", "alert('Please select Size of Pizza')", true);
}
else
{
if (ItemSmall == String.Empty)
{
ItemSmall = "-";
}
if (ItemMedium == String.Empty)
{
ItemMedium = "-";
}
if (ItemLarge == String.Empty)
{
ItemLarge = "-";
}
String Query = "insert into Temp_cart_New values('" + UserId + "','" + ProductID + "','" +
Convert.ToString(ItemSmall) + "','" + Convert.ToString(ItemMedium) + "','" +
Convert.ToString(ItemLarge) + "','" +
Convert.ToInt16(Qty) + "','" + Total + "','" + DateTime.Now
+ "')";
OnlinePizzaOrder.Connection.excute_query(Query);
Response.Redirect("Item.aspx");
}
}
catch (Exception ex)
{
Response.Write(Convert.ToString(ex.Message));
}
finally
{
}
}
}