Hello, I'm currently developing a application in VB.Net. I'm using the DataGridView to display my data on the form. I have a EDIT button on the module and I need to know how can I populate a selected record into the textboxes from the DataGridView. Hope you could understand my question. Thank you very much.

This is the current code which I created, but when I hit the edit it says (Message="Invalid attempt to call Read when reader is closed.")

Private Sub cmdEdit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdEdit.Click
        SQL = "SELECT * FROM Admin_Table"
        Dim DA As New SqlDataAdapter(SQL, Conn1)
        Dim DS As New DataSet
        Dim cmdBuilder As New SqlCommandBuilder(DA)

        DA.Fill(DS)

        If DS.Tables(0).Rows.Count > 0 Then
            If MsgBox("Edit this Administrator Details?", vbExclamation + vbYesNo, "Edit Administrator Details") = vbYes Then

                Call drawerOpen()
                Call cboOption()
                detailbox.Visible = True
                cmdUpdate.Visible = True
                cmdSave.Visible = False
                txtName.ReadOnly = True
                txtUsername.ReadOnly = True

                Conn1.Open()
                rs.Read()
                txtID.Text = rs("admin_ID")
                txtName.Text = rs("admin_Name")
                txtUsername.Text = rs("admin_Username")
                txtPassword.Text = rs("admin_Password")
                cboDesignation.Text = rs("admin_Designation")
                'DA.Update(DS)

                rs.Close()
                Conn1.Close()
            End If
        Else
            dummy = MsgBox("No Administrator Details found!", vbCritical, "Error")
            rs.Close()
            Conn1.Close()
        End If
    End Sub
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.