0

I have bind the DataGridview with DB. To add the data from textboxes to DataGrid, I use the foll. code-

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Try
            Dim row0 As String() = {TextBox1.Text, TextBox2.Text, TextBox3.Text}
            DataGridView1.Rows.Add(row0)
            row0 = Nothing
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub

Error is coming
Rows cannot be programmatically added to the DataGridView's rows collection when the control is data-bound

there is no any way to add data to the Gridview if we bound it to the Database.

2
Contributors
1
Reply
4
Views
7 Years
Discussion Span
Last Post by TomW
0

The DataGridView control is simply a means of displaying data from an underlying datasource such as a DataSet/DataTable/Array etc.... You do not want to add rows directly to the DataGridView, you want to add rows to the underlying datasource. Such as if you have a datatable attached, it is the datatable you want to add a row too.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.