I created tab pages with this,

cmd.CommandText = "Select * from StuInfo where StuID ='" & SelectedID & "' order by PayDateDB desc"
cmd.Parameters.AddWithValue("@StuID ", SelectedID)
DA.SelectCommand = cmd
DT = DS.Tables(0)
RecCount = DT.Rows.Count


If RecCount > 0 Then

    For Each DR In DT.Rows
        newPage = New TabPage
        StuClassTXT = New TextBox
        StuNameTXT.Text = DR("STUClassDB") ' MS-Access Field Name
        StuAMTXT = New TextBox
        StuAMTXT.Text = DR("StuAMTXTDB") ' MS-Access Field Name
        RecCount += -1


When change(Edit) details any tab page,

How can I use UPDATE command to Database

Edited 3 Years Ago by Reverend Jim: fixed indentation

You first need a way to refrence the student for the update. An ID column works perfect for this.

You will need to reference the text box values, therefore, need to name the nextboxes something that can be descriptive.

For example:

            For Each DR As DataRow In DT.Rows
                Dim tpNew As New TabPage
                tpNew.Name = DR("StuID") ' Will name the tab after the ID column value

                Dim txtStudentName As New TextBox
                With txtStudentName
                    .Name = "txtStudentName"
                    .Text = DR("STUNameDB")
                    .Size = New Size(76, 12)
                    .Location = New Point(5, 5)
                End With

                Dim txtStudentClass As New TextBox
                With txtStudentClass
                    .Name = "txtStudentClass"
                    .Text = DR("STUClassDB")
                    .Size = New Size(76, 12)
                    .Location = New Point(5, 30)
                End With

                Dim txtStudentAmount As New TextBox
                With txtStudentAmount
                    .Name = "txtStudentAmount"
                    .Text = DR("StuAMTXTDB")
                    .Size = New Size(76, 12)
                    .Location = New Point(5, 42)
                End With


When you press the save button you will need to call the active tab page:

Dim activePage As TabPage = TabControl1.SelectedTab

Then issue the update:

Dim iStudentID As Integer = CInt(activePage.Name)
Dim txtStudentName As TextBox = TryCast(activePage.Controls("txtStudentName"),TextBox) 
Dim txtStudentClass As TextBox = TryCast(activePage.Controls("txtStudentClass"),TextBox) 
Dim txtStudentAmount As TextBox = TryCast(activePage.Controls("txtStudentAmount"),TextBox)

Dim q as String = "UPDATE StuInfo SET STUNameDB='{0}',STUClassDB='{1},StuAMTXTDB='{2} WHERE StuID={3}"

q = String.Format(q,txtStudentName.Text,txtStudentClass.Text,txtStudentAmount.Text,iStudentID")
cmd.CommandText = q
This article has been dead for over six months. Start a new discussion instead.