gtjr92
Programmer
- May 26, 2004
- 96
I want my code to look at each control i have, find the data in the control, and then insert it to a DB. This works, except I have only got it to work with a for each loop, which i don't want. Of course this inserts the same data 9 times which is how many rows I have. which i don't want
If I don't use for each then I get the message for my dgi.findcontrol that says "Variable is used before it has been assigned a value". I tried using a few different IF Then commands to no avail. Here is my code. Thanks
If I don't use for each then I get the message for my dgi.findcontrol that says "Variable is used before it has been assigned a value". I tried using a few different IF Then commands to no avail. Here is my code. Thanks
Code:
Sub InsertNew(ByVal sender As Object, ByVal e As EventArgs)
Dim dgi As DetailsViewRow
For Each dgi In dviewINnew.Rows
' Find the Selected Class Name ID Value
Dim ClassIDup As Integer = CType(dgi.FindControl("ddlClass"), DropDownList).SelectedValue
Dim Titleup As String = CType(dgi.FindControl("txtTitle"), TextBox).Text
Dim Descriptionup As String = CType(dgi.FindControl("txtDescription"), TextBox).Text
Dim TeacherIDup As Integer = CType(dgi.FindControl("ddlTeacher"), DropDownList).SelectedValue
Dim Totalpointsup As Decimal = CType(dgi.FindControl("txtTotalPoints"), TextBox).Text
Dim AssignDateup As Date = CType(dgi.FindControl("calDateassign"), Calendar).SelectedDate
Dim DueDateup As Date = CType(dgi.FindControl("calDuedate"), Calendar).SelectedDate
'Create a New Insert Paremeter for the above values
dsNewAssign.InsertParameters.Add("agTitle", Titleup)
dsNewAssign.InsertParameters.Add("agDescription", Descriptionup)
'dsClassID.InsertParameters.Add("AssignmentsID", ID)
dsNewAssign.InsertParameters.Add("agTotalPoints", Totalpointsup)
dsNewAssign.InsertParameters.Add("agDateAssigned", AssignDateup)
dsNewAssign.InsertParameters.Add("agDueDate", DueDateup)
dsNewAssign.InsertParameters.Add("agClassID", ClassIDup)
dsNewAssign.InsertParameters.Add("agTeacherID", TeacherIDup)
'Response.Write(dsUpdateAssign.Update)
'Response.End()
dsNewAssign.Insert()
dsNewAssign.InsertParameters.Clear()
Next
Response.Redirect("~/Teachers/assignUPD.aspx")
End Sub