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
Najaf Haider
NA
61
1.1k
The conversion of a varchar data type to a datetime data
Dec 13 2018 9:44 AM
protected void Button1_Click(object sender, EventArgs e)
{
ObjConn.Open();
SqlCommand ObjCom = new SqlCommand("Insert into Testing(Date) values('" + DateTime.Now.ToString() + "')", ObjConn);
if (ObjCom.ExecuteNonQuery() == 1)
{
Response.Write("<!-- Inject Script Filtered -->");
}
ObjConn.Close();
BindDataTable();
}
This is my code i'm just simply insertDatetime.Now in sql database but it gives me error in DB table Date type is datetime.
It's working in my laptop but when i run this same code in another PC than it gives me this error.
The conversion of a varchar data type to a datetime data type resulted in an out-of-range value.
The statement has been terminated.
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: The conversion of a varchar data type to a datetime data type resulted in an out-of-range value.
The statement has been terminated.
Source Error:
Line 25: SqlCommand ObjCom = new SqlCommand("Insert into Testing(Date) values('" + DateTime.Now.ToString() + "')", ObjConn); Line 26: Line 27: if (ObjCom.ExecuteNonQuery() == 1)
Reply
Answers (
2
)
MEF concept in c#
How to add asterisk in data table new row in asp.net C#?