Click here to Skip to main content
15,892,809 members

How to Update Dynamic Textbox value to SQL?

Member 9989624 asked:

Open original thread
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
Tags: Visual Basic

Plain Text
ASM
ASP
ASP.NET
BASIC
BAT
C#
C++
COBOL
CoffeeScript
CSS
Dart
dbase
F#
FORTRAN
HTML
Java
Javascript
Kotlin
Lua
MIDL
MSIL
ObjectiveC
Pascal
PERL
PHP
PowerShell
Python
Razor
Ruby
Scala
Shell
SLN
SQL
Swift
T4
Terminal
TypeScript
VB
VBScript
XML
YAML

Preview



When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
  4. Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the http://www.codeproject.com/info/cpol10.aspx.



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