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
DA.Fill(DS)
DT = DS.Tables(0)
RecCount = DT.Rows.Count

TabControl1.TabPages.Clear()

If RecCount > 0 Then

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

Endif

When change(Edit) details any tab page,

How can I use UPDATE command to Database

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

                tpNew.Controls.Add(txtStudentName)
                tpNew.Controls.Add(txtStudentClass)
                tpNew.Controls.Add(txtStudentAmount)
                TabControl1.TabPages.Add(tpNew)
            Next

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
cmd.ExecuteNonQuery
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.