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
Rahul Lakshakar
NA
199
42.1k
Insert datetime into databse
Oct 15 2016 12:19 PM
string constr = ConfigurationManager.ConnectionStrings["conn"].ConnectionString;
SqlConnection con = new SqlConnection(constr);
con.Open();
string stime = Text_Stime.Text;
string etime = Text_Etime.Text;
DateTime Sdatetime = new DateTime();
Sdatetime = DateTime.ParseExact(Text_Stime.Text, "yyyy-MM-dd hh:mm tt", null);
DateTime Edatetime = new DateTime();
Edatetime = DateTime.ParseExact(Text_Etime.Text, "yyyy-MM-dd hh:mm tt", null);
string insertData = "insert into ExamDetail (ExamName, SubjectName, Duration, StartTime, EndTime, NegativeMark, QusNo, QusMarks) values (@EName, @SubName, @DUR, @ST, @ET, @NM, @QN,@QM)";
SqlCommand com = new SqlCommand(insertData, con);
com.Parameters.AddWithValue("@EName", DropExamName.SelectedItem.Text);
com.Parameters.AddWithValue("@SubName", DropSubName.SelectedItem.Text);
com.Parameters.AddWithValue("@DUR", DropDuration.SelectedItem.Text);
com.Parameters.AddWithValue("@ST", Sdatetime);
com.Parameters.AddWithValue("@ET", Edatetime);
com.Parameters.AddWithValue("@NM", RadioNegativeMarks.SelectedItem.Text);
com.Parameters.AddWithValue("@QN", Text_question_no.Text);
com.Parameters.AddWithValue("@QM", text_question_marks.Text);
com.ExecuteNonQuery();
I am trying to insert datetime into database. But it showing an error "String was not recognized as a valid DateTime." I am using above code. I am using textbox's TextMode="DateTimeLocal".
Please Help me...How can i remove this error?
Reply
Answers (
6
)
Regarding the MVVM with WPF
how can i keep my user control ?