如何将动态文本框值更新为SQL? [英] How to Update Dynamic Textbox value to SQL?

查看:89
本文介绍了如何将动态文本框值更新为SQL?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我有2个动态创建的按钮1个动态创建的文本框和1个动态创建的标签。



当我按下一个按钮时,文本框的值将增加。并且以相同的方式当按下其他按钮时,文本框值将减少。



现在我需要在按下按钮时直接更新SQL。当它得到更新时,应该从标签框中查找sql​​中的名称。



我在代码下面,它得到了更新但是只有最后一个标签的sql数据是得到更新。请帮帮我。



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.

 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

推荐答案

impadmins123; Persist Security Info = True;用户ID = simp;初始目录=员工信息;数据源= SRAVI6
con.Open()
cmd2。 Connection = con
cmd2.CommandText = update QueueManagement set QueueHandler ='& txt .Text& 'where AgentName ='& lbl.Text& '
cmd2.ExecuteNonQuery()
con.Close()
< span class =code-keyword>结束 Sub
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


这篇关于如何将动态文本框值更新为SQL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆