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:
|
Source File: c:\Users\Dixit\Desktop\DOWNLOADED PROJECT\online-e\online-e\78\onlineexamination\Register.aspx.cs Line: 31
Stack Trace:
|
Version Information: Microsoft .NET Framework Version:2.0.50727.8009; ASP.NET Version:2.0.50727.8015
HERE IS MY register.aspx file :
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Register.aspx.cs" Inherits="Register" %>
BorderWidth="2px" Height="416px" Style="z-index: 100; left:96px; position: absolute;
top: 32px" Width="792px" BackImageUrl="~/pictures/img30.jpg">
Registration Form
Style="z-index: 110; left: 0px; position: absolute; top: 56px" Text="Personnel Details"
Width="784px">
Style="z-index: 116; left: 0px; position: absolute; top: 232px" Text="Login Details"
Width="784px">
Style="z-index: 102; left: 72px; position: absolute; top: 136px">
HERE IS MY register.aspx.cs file :
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
public partial class Register : System.Web.UI.Page
{
SqlConnection con = new SqlConnection();
public Register()
{
con.ConnectionString = ConfigurationManager.ConnectionStrings["ConnectionString"].ToString();
}
protected void Page_Load(object sender, EventArgs e)
{
con.Open();
}
protected void Button1_Click(object sender, EventArgs e)
{
Session["sid"] = TextBox6.Text;
string s1 = "insert into Registration values('"+TextBox1.Text+"','"+TextBox2.Text+"','"+RadioButtonList1.SelectedItem.Text+"','"+DropDownList3.SelectedItem.Text+"','"+TextBox5.Text+"','"+TextBox6.Text+"','"+TextBox7.Text+"','"+TextBox8.Text+"','"+DropDownList1.SelectedItem.Text+"','"+DropDownList2.SelectedItem.Text+"','"+TextBox9.Text+"')";
SqlCommand cmd = new SqlCommand(s1, con);
cmd.ExecuteNonQuery();
Response.Redirect("RegAck.aspx");
}
protected void Button2_Click(object sender, EventArgs e)
{
TextBox1.Text = "";
TextBox2.Text = "";
TextBox5.Text = "";
TextBox6.Text = "";
TextBox7.Text = "";
TextBox8.Text = "";
TextBox9.Text = "";
DropDownList1.SelectedItem.Text = DropDownList1.Items[0].Text;
DropDownList2.SelectedItem.Text = DropDownList2.Items[0].Text;
DropDownList3.SelectedItem.Text = DropDownList3.Items[0].Text;
RadioButtonList1.Items[0].Selected = false;
RadioButtonList1.Items[1].Selected = false;
}
protected void TextBox5_TextChanged(object sender, EventArgs e)
{
}
}
11 Replies
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Amit Kumar SinghPosted Mar 16, 2016, 7:59 AM
stelle thomasPosted Mar 16, 2016, 7:45 AM
stelle thomasPosted Mar 16, 2016, 7:32 AM
Amit Kumar SinghPosted Mar 16, 2016, 7:07 AM
stelle thomasPosted Mar 16, 2016, 6:50 AM
Amit Kumar SinghPosted Mar 16, 2016, 6:49 AM
Chandu KumawatPosted Mar 16, 2016, 6:44 AM
if you want to use
CAST, replace with:Amit Kumar SinghPosted Mar 16, 2016, 6:20 AM
stelle thomasPosted Mar 16, 2016, 5:47 AM
Chandu KumawatPosted Mar 16, 2016, 5:23 AM
Amit Kumar SinghPosted Mar 16, 2016, 2:30 AM