i am trying to add a edit button where the data displayed in the textboxes from the selected record in the datagridview on vb gets update if i change any details when i press the edit button. problem is when i click the button it says 'There is no row at position 0' on the line............COMP4DataSet.Tables("StockControl").Rows(selecteditem).Item("Product Type") = txtProductType.Text

here is my code:

'edit button

Dim selecteditem As Integer

        SelectedItem = grdStockControl.CurrentRow.Index

      COMP4DataSet.Tables("Stock Control").Rows(selecteditem).Item("Product Type") = txtProductType.Text
        COMP4DataSet.Tables("Stock Control").Rows(selecteditem).Item("Make") = txtMake.Text
        COMP4DataSet.Tables("Stock Control").Rows(selecteditem).Item("PartNo") = txtPartNo.Text
        COMP4DataSet.Tables("Stock Control").Rows(selecteditem).Item("Model") = txtModel.Text
        COMP4DataSet.Tables("Stock Control").Rows(selecteditem).Item("WholesalerPrice") = txtWholesalerPrice.Text
        COMP4DataSet.Tables("Stock Control").Rows(selecteditem).Item("RetailPrice") = txtRetailPrice.Text
        COMP4DataSet.Tables("Stock Control").Rows(selecteditem).Item("SupplierUsed") = txtSupplierUsed.Text
        COMP4DataSet.Tables("Stock Control").Rows(selecteditem).Item("Quantity") = txtQuantity.Text
        COMP4DataSet.Tables("Stock Control").Rows(selecteditem).Item("ReOrderLevel") = txtReOrderLevel.Text

        dbdataAdapter.Update(COMP4DataSet, "dtStockControl")

        MsgBox("Data was successfully edited", "Stock Control")

    End Sub

Recommended Answers

All 2 Replies

>when i click the button it says 'There is no row at position 0' on the
Make sure that COMP4DataSet.Tables("Stock Control") table is not empty.

IF  COMP4DataSet.Tables("Stock Control").Rows.Count<>0 Then
   ....
End If

>when i click the button it says 'There is no row at position 0' on the
Make sure that COMP4DataSet.Tables("Stock Control") table is not empty.

IF  COMP4DataSet.Tables("Stock Control").Rows.Count<>0 Then
   ....
End If

The thing i dont understand is there is at least 10 rows on my datagridview as well as my database and is telling me that theres no rows am not sure where i am going wrong.

at the if statement now means the edit button does nothing because it thinks there is no rows

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.