ASP.NET GridView将数据保存到数据库

时间:2013-04-26 05:41:42

标签: asp.net gridview

我有一个grid的TimeTable条目。
列列表是这样的。

S.No  Slot Name  Monday  Tuesday  Wednesday  Thursday  Friday
====  =========  ======= =======  =========  ========  ======== 

插槽名称已从数据库加载了值。

用户可以在任何时间段(即时间段)输入任何一天的数据。(用户可以通过点击每列内部添加按钮显示的弹出窗口添加数据)。

如果用户未在任何一天输入,则不应将数据保存到数据库中。我该如何检查?

P.S。此页面中的保存操作首先将数据保存到父表中,该表包含学校,班级,学期,科等信息。保存后,每天的各个详细信息将保存到另一个表中。


@Syed,这是我的插入代码。

Dim sFacultyLabelDetail As String = "lbl" & sDay & "Faculty"
Dim lblFacNameDetail As System.Web.UI.WebControls.Label = row.FindControl(sFacultyLabel)

Dim sSubjectLabelDetail As String = "lbl" & sDay & "Subject"
Dim lblSubjectNameDetail As System.Web.UI.WebControls.Label = row.FindControl(sSubjectLabel)

dsGetTimeTableDetailID = (From t1 In dbl.TimeTableDetails Where t1.TimeTableBreakUpID = dsSaveTimeTableBreakUpDetails And t1.Date = stDate Select t1.TimeTableDetailID).FirstOrDefault.ToString

If (dsGetTimeTableDetailID = 0 And (Trim(lblSubjectNameDetail.Text) <> "" Or Trim(lblFacNameDetail.Text) <> "" Or Trim(lblIsExternal.Text) <> "")) Then
    dsSaveTimeTableDetailsForView = dbl.usp_InsertTimeTableDetailsForViewTimeTable(0, dsSaveTimeTableBreakUpDetails, Val(lblFacID.Text), Trim(lblFacNameDetail.Text), Val(lblSubjectID.Text), Trim(lblSubjectNameDetail.Text), stDate.Date, Trim(lblIsExternal.Text), sDayName, "Y", sUserName, DateTime.Now).ReturnValue
ElseIf (dsGetTimeTableDetailID <> 0) And (Trim(lblSubjectNameDetail.Text) = "" And (Trim(lblFacNameDetail.Text) = "" And Trim(lblIsExternal.Text) = "")) Then
    dsSaveTimeTableDetailsForView = dbl.usp_UpdateTimeTableDetailsForViewTimeTable(dsGetTimeTableDetailID, dsSaveTimeTableBreakUpDetails, Val(lblFacID.Text), Trim(lblFacNameDetail.Text), Val(lblSubjectID.Text), Trim(lblSubjectNameDetail.Text), stDate.Date, Trim(lblIsExternal.Text), sDayName, "N", sUserName, DateTime.Now).ReturnValue
ElseIf (dsGetTimeTableDetailID <> 0 And (Trim(lblSubjectNameDetail.Text) <> "" Or Trim(lblFacNameDetail.Text) <> "" Or Trim(lblIsExternal.Text) <> "")) Then
    dsSaveTimeTableDetailsForView = dbl.usp_UpdateTimeTableDetailsForViewTimeTable(dsGetTimeTableDetailID, dsSaveTimeTableBreakUpDetails, Val(lblFacID.Text), Trim(lblFacNameDetail.Text), Val(lblSubjectID.Text), Trim(lblSubjectNameDetail.Text), stDate.Date, Trim(lblIsExternal.Text), sDayName, "Y", sUserName, DateTime.Now).ReturnValue    
End If

此处 sDay 是网格中的标题名称(星期一/星期二......)

0 个答案:

没有答案