isdc
asked on
Updating an arraylist to SQL Database
I had posted here last week regarding an issue "VeryNiceMan" had helped me.
https://www.experts-exchange.com/questions/21864141/Updating-dynamic-controls-to-a-database-VB-NET.html
NOW i'm stuck trying to get this update a database. For some reason my eyes just aren't seeing where to begin.
I've tried (and successfully i think) gotten things into an arraylist, but it's not updating the database as i would like to see it.
Here's some of my "updated" code.
-- This is where i dynamically create controls based on a checkboxlist of 13 items. This part seems to be working as intended.
Private Sub CreateMyControls()
Dim i As Integer
For i = 0 To cblPatientGoals.Items.Coun t - 1
If cblPatientGoals.Items(i).S elected Then
Dim myLabel As New Label
myLabel.Text &= cblPatientGoals.Items(i).T ext
Dim myRadioButton As New RadioButtonList
myRadioButton.Items.Add(Ne w ListItem("Met", "Met"))
myRadioButton.Items.Add(Ne w ListItem("Unmet", "Unmet"))
myRadioButton.RepeatDirect ion = RepeatDirection.Horizontal
Dim myTextBox As New TextBox
myTextBox.Style("Width") = "350px"
myRadioButton.ID = "cGoals" & (i+1)
myTextBox.ID = "tGoals" & (i+1)
myLabel.ID = "lGoals" & (i+1)
Panel1.Controls.Add(New LiteralControl("<tr><td>") )
Panel1.Controls.Add(myLabe l)
Panel1.Controls.Add(New LiteralControl("</td>"))
Panel1.Controls.Add(New LiteralControl("<td>"))
Panel1.Controls.Add(myRadi oButton)
Panel1.Controls.Add(New LiteralControl("</td>"))
Panel1.Controls.Add(New LiteralControl("<td>"))
Panel1.Controls.Add(myText Box)
Panel1.Controls.Add(New LiteralControl("</td></tr> "))
End If
Next
End Sub
--This is the code that (obviously) executes when the Submit Button is pushed. This is where i need some direction.
In my arraylist where i write out "Response.Write(CStr(al.It em(x)))" i can see the items i want to update, but it's only updating one of the 2 items in the checkboxlist 6 times. I'll paste more info as needed.
Sub Button1_Click(Sender as Object, E as Eventargs)
Dim i As Integer
Dim t As TextBox
Dim l As Label
Dim c As RadioButtonList
Dim al As New ArrayList()
'For x = 0 To cblPatientGoals.Items.Coun t - 1
'If cblPatientGoals.Items(x).S elected Then
For i = 0 To Panel1.Controls.Count - 1
If Panel1.Controls(i).GetType Is GetType(Label) Then
l = CType(Panel1.Controls(i), Label)
'Response.Write(l.ID & "-->" & l.Text.Trim & "<BR>")
al.Insert(0, l.text.trim)
End If
If Panel1.Controls(i).GetType Is GetType(RadioButtonList) Then
c = CType(Panel1.Controls(i), RadiobuttonList)
'Response.Write(c.ID & "-->" & c.SelectedItem.Text & "<BR>")
al.Insert(1, c.SelectedItem.Text)
'Response.Write(c.ID & "-->" & c.Items(0).Selected & "-->" & c.Items(1).Selected & "<BR>")
End If
If Panel1.Controls(i).GetType Is GetType(TextBox) Then
t = CType(Panel1.Controls(i), TextBox)
'Response.Write(t.ID & "-->" & t.Text.Trim & "<BR>")
al.Insert(2, t.text.trim)
End If
Next
Dim x As Integer
For x = 0 To al.Count - 1
Response.Write(CStr(al.Ite m(x)))
Dim myConnection as New SQLConnection(Configuratio nSettings. appSetting s("connStr ing"))
myConnection.Open()
Dim myInsert as String = "INSERT INTO tblEducationGoals (goal_id, goal_MetUnmet, goal_text)" & _
"VALUES ('" & al.item(0) & "', '" & al.item(1) & "', '" & al.item(2) & "')"
Dim Cmd as New SQLCommand(MyInsert, myConnection)
cmd.ExecuteNonQuery
MyConnection.Close()
Next
End Sub
Thanks again.
dc.
https://www.experts-exchange.com/questions/21864141/Updating-dynamic-controls-to-a-database-VB-NET.html
NOW i'm stuck trying to get this update a database. For some reason my eyes just aren't seeing where to begin.
I've tried (and successfully i think) gotten things into an arraylist, but it's not updating the database as i would like to see it.
Here's some of my "updated" code.
-- This is where i dynamically create controls based on a checkboxlist of 13 items. This part seems to be working as intended.
Private Sub CreateMyControls()
Dim i As Integer
For i = 0 To cblPatientGoals.Items.Coun
If cblPatientGoals.Items(i).S
Dim myLabel As New Label
myLabel.Text &= cblPatientGoals.Items(i).T
Dim myRadioButton As New RadioButtonList
myRadioButton.Items.Add(Ne
myRadioButton.Items.Add(Ne
myRadioButton.RepeatDirect
Dim myTextBox As New TextBox
myTextBox.Style("Width") = "350px"
myRadioButton.ID = "cGoals" & (i+1)
myTextBox.ID = "tGoals" & (i+1)
myLabel.ID = "lGoals" & (i+1)
Panel1.Controls.Add(New LiteralControl("<tr><td>")
Panel1.Controls.Add(myLabe
Panel1.Controls.Add(New LiteralControl("</td>"))
Panel1.Controls.Add(New LiteralControl("<td>"))
Panel1.Controls.Add(myRadi
Panel1.Controls.Add(New LiteralControl("</td>"))
Panel1.Controls.Add(New LiteralControl("<td>"))
Panel1.Controls.Add(myText
Panel1.Controls.Add(New LiteralControl("</td></tr>
End If
Next
End Sub
--This is the code that (obviously) executes when the Submit Button is pushed. This is where i need some direction.
In my arraylist where i write out "Response.Write(CStr(al.It
Sub Button1_Click(Sender as Object, E as Eventargs)
Dim i As Integer
Dim t As TextBox
Dim l As Label
Dim c As RadioButtonList
Dim al As New ArrayList()
'For x = 0 To cblPatientGoals.Items.Coun
'If cblPatientGoals.Items(x).S
For i = 0 To Panel1.Controls.Count - 1
If Panel1.Controls(i).GetType
l = CType(Panel1.Controls(i), Label)
'Response.Write(l.ID & "-->" & l.Text.Trim & "<BR>")
al.Insert(0, l.text.trim)
End If
If Panel1.Controls(i).GetType
c = CType(Panel1.Controls(i), RadiobuttonList)
'Response.Write(c.ID & "-->" & c.SelectedItem.Text & "<BR>")
al.Insert(1, c.SelectedItem.Text)
'Response.Write(c.ID & "-->" & c.Items(0).Selected & "-->" & c.Items(1).Selected & "<BR>")
End If
If Panel1.Controls(i).GetType
t = CType(Panel1.Controls(i), TextBox)
'Response.Write(t.ID & "-->" & t.Text.Trim & "<BR>")
al.Insert(2, t.text.trim)
End If
Next
Dim x As Integer
For x = 0 To al.Count - 1
Response.Write(CStr(al.Ite
Dim myConnection as New SQLConnection(Configuratio
myConnection.Open()
Dim myInsert as String = "INSERT INTO tblEducationGoals (goal_id, goal_MetUnmet, goal_text)" & _
"VALUES ('" & al.item(0) & "', '" & al.item(1) & "', '" & al.item(2) & "')"
Dim Cmd as New SQLCommand(MyInsert, myConnection)
cmd.ExecuteNonQuery
MyConnection.Close()
Next
End Sub
Thanks again.
dc.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Yes, apologies on my lack of attentiveness to this. Involvement in other things prevented me from trying this. I accept this as well and i thank everyone for the assistance with this. I am happy to see a board that is monitored so closely.
public class clsResult
GoalID as STRING '''' at no point did you say it was an integer, just assumed!
GoalMet as String
GoalText as String
End Class