I have a sqlDtSrc that I want to edit the data of the table with it. I write the below code but it doesn't update my table and doesn't have any error.
the data type of ExamTime field in SQL is time(7) and I use DateTime in visual studio. I do not really know what type of data
I will choose in visual studio for ExamTime field.
<asp:SqlDataSource ID="sqlDtSrcEditCourse" runat="server"
ConnectionString="<%$ ConnectionStrings:KDUIS-v1ConnectionString %>"
SelectCommand ="SELECT EDU_SubjectStudy.Title AS SubjectStudyTitle, EDU_SubjectStudy.Id AS SubjectStudyId, EDU_Lesson.Title AS LessonTitle, EDU_Course.Id AS CourseId, EDU_Course.ExamDate, EDU_Course.ExamTime, EDU_Course.RoomId FROM EDU_SubjectStudyLesson_Course INNER JOIN EDU_SubjectStudy_Lesson ON EDU_SubjectStudyLesson_Course.SubjectStudyLessonId = EDU_SubjectStudy_Lesson.Id INNER JOIN EDU_Course ON EDU_SubjectStudyLesson_Course.CourseId = EDU_Course.Id INNER JOIN EDU_SubjectStudy ON EDU_SubjectStudy_Lesson.SubjectStudyId = EDU_SubjectStudy.Id INNER JOIN EDU_Lesson ON EDU_SubjectStudy_Lesson.LessonId = EDU_Lesson.Id WHERE (EDU_SubjectStudyLesson_Course.CourseId = @CourseId)"
UpdateCommand="Update EDU_Course SET [ExamDate]=@ExamDate,[ExamTime]=@ExamTime,[RoomId]=@RoomId WHERE id=@id"
OnUpdating="sqlDtSrcEditCourse_Updating">
<SelectParameters>
<asp:ControlParameter ControlID="LblCourseId" Name="CourseId" PropertyName="Text" />
</SelectParameters>
<UpdateParameters>
<asp:Parameter Name="ExamDate" Type="DateTime" />
<asp:Parameter Name="ExamTime" Type="DateTime" />
<asp:ControlParameter ControlID="ListRoom" Name="RoomId" PropertyName="Text" Type="Int16" />
<asp:Parameter Name="id" />
</UpdateParameters>
</asp:SqlDataSource>
protected void sqlDtSrcEditCourse_Updating(object sender, SqlDataSourceCommandEventArgs e)
{
string starttime1 = ListStartHour1.SelectedItem + Label11.Text + ListStartMinute1.SelectedItem;
DateTime StartTime11;
StartTime11 = DateTime.Parse(starttime1);
try
{
int day = Convert.ToInt32(txtday.Text);
int month = Convert.ToInt32(txtmonth.Text);
int year = Convert.ToInt32(txtyear.Text);
System.Globalization.PersianCalendar faDate = new System.Globalization.PersianCalendar();
e.Command.Parameters["@ExamDate"].Value = faDate.ToDateTime(year, month, day, 23, 0, 0, 0);
e.Command.Parameters["@ExamTime"].Value = StartTime11;
}
catch { }
}
protected void BtnEdit_Click(object sender, EventArgs e)
{
sqlDtSrcEditCourse.Update();
}