I am using the code below to bind my Gridview to a datatable and the code works well. However I now want to add data to the datable and its giving me an error "Rows cannot be programmatically added to the DataGridView's rows collection when the control is data-bound.".
So now I want to add the new row to the datatable instead. I want to insert this information into the datatable but from another form and I wanted some help on how i can go about it.Currently this is where I am at,
Dim myDS As DataSet = MstFileCompanyProductsGrid.ds
Dim myDt As DataTable = myDS.Tables(0)
I wanted to know how I can implement this code that I got from Here into my work
Dim newCustomersRow As SampleDataSet.CustomersRow
newCustomersRow = SampleDataSet.Customers.NewCustomersRow
newCustomersRow.CustomerID = "1234"
newCustomerRow.CompanyName = "Sample Works"
SampeDataSet.Customers.Rows.Add(newCustomersRow)
So this is the code I used to fill the Gridview
Private Sub btnTest_Click(sender As System.Object, e As System.EventArgs) Handles btnTest.Click
Dim myConn As OleDbConnection = frmLogIn.Conn
Dim sql As String = "select * from ProductRawMaterial1"
Dim oledbAdapter As OleDbDataAdapter
Try
myConn.Open()
oledbAdapter = New OleDbDataAdapter(sql, myConn)
oledbAdapter.Fill(ds)
RadGridView2.DataSource = ds.Tables(0)
RadGridView2.TableElement.BestFitColumns()
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Sub