Click here to Skip to main content
16,020,188 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I have 2 dynamically created buttons 1 dynamically created textbox and 1 dynamically created label.

When i press one button the value of the textbox will get incremented. and in the same fashion when ipress other button the textbox value will get decremented.

Now i need to update SQL directly when i press the Buttons. When its getting updated it should look for the name in sql from the label box.

I below code , its getting updated however only last label's sql data is getting updated. Please help me.

VB
 Dim i As Integer = new_Textboxes.Length
Dim i As Integer = new_Textboxes.Length
 Private but1() As Button = {}
 Private new_Textboxes() As TextBox = {}



 Dim lb As Integer
        For lb = 1 To ListBox1.Items.Count
            For Each listboxitem In ListBox1.Items
                lbl = New Label
                lbl.Location = New Point(300, 200 + (lb * 25))
                lbl.Name = "Label" & lb
                lbl.Width = 155
                lbl.Text = ListBox1.GetItemText(listboxitem)
                Me.Controls.Add(lbl)
                lb = lb + 1
            Next listboxitem
        Next lb


but1(m) = New Button
            With but1(m)
                .Name = "NewButton" & m.ToString()
                If but1.Length < 2 Then
                    .SetBounds(500, 222, 26, 20)
                Else
                    .Left = but1(m - 1).Left
                    .Top = but1(m - 1).Top + but1(m - _
                        1).Height + 6
                    .Size = but1(m - 1).Size
                End If
                .Tag = m
                .Text = "+"
            End With
            Me.Controls.Add(but1(m))
            AddHandler but1(m).Click, AddressOf oBtnAdd_Click

            but2(n) = New Button
            With but2(n)
                .Name = "NewButton" & n.ToString()
                If but2.Length < 2 Then
                    .SetBounds(590, 222, 26, 20)
                Else
                    .Left = but2(n - 1).Left
                    .Top = but2(n - 1).Top + but2(n - _
                        1).Height + 6
                    .Size = but2(n - 1).Size
                End If
                .Tag = n
                .Text = "-"
            End With
            Me.Controls.Add(but2(n))
            AddHandler but2(n).Click, AddressOf oBtnSubst_Click

new_Textboxes(i) = New TextBox
            With new_Textboxes(i)
                .Name = "NewTextBox" & i.ToString()
                If new_Textboxes.Length < 2 Then
                    .SetBounds(545, 225, 25, 25)
                Else
                    .Left = new_Textboxes(i - 1).Left
                    .Top = new_Textboxes(i - 1).Top + new_Textboxes(i - _
                        1).Height + 6
                    .Size = new_Textboxes(i - 1).Size
                End If
                .Tag = i
                .Text = 0
            End With
            Me.Controls.Add(new_Textboxes(i))

 Public Sub oBtnAdd_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles oBtnAdd.Click
        Dim btn As Button = sender
        Dim txt As TextBox = CType(Me.Controls("NewTextBox" & btn.Tag), TextBox)
        Dim count As Integer = Integer.Parse(txt.Text)
        txt.Text = count + 1
        Dim con As New OleDb.OleDbConnection()
        Dim cmd2 As New OleDb.OleDbCommand()
        con.ConnectionString = "Provider=SQLOLEDB.1;Password=$impadmins123;Persist Security Info=True;User ID=simp;Initial Catalog=Employee Information;Data Source=SRAVI6"
        con.Open()
        cmd2.Connection = con
        cmd2.CommandText = "update QueueManagement set QueueHandler='" & txt.Text & "' where AgentName='" & lbl.Text & "'"
        cmd2.ExecuteNonQuery()
        con.Close()
    End Sub
Posted
Comments
[no name] 27-Apr-13 22:44pm    
That is probably because you are not setting the variable lbl to anything other that what it was last set at. Debug it. Oh and stop using string concatenation to construct SQL injection attack code, use parameterized queries.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900