I have a piece of code that works for adding multiple rows to a dataset but I think that it is a lot of code and thought maybe someone may know a better way of doing it. I need to add rows to the dataset based on the selection of a combo box. ie if the user selects 15 the the program adds 15 rows to the dataset. not too bad but if 45+ rows are needed then that's a lot of code. anyway see what you think and any help would be appreciated!

Case cboQty.SelectedItem = 3
                Try
                    Dim dr As DataRow
                    Dim dr2 As DataRow
                    Dim dr3 As DataRow

                    dr = ds.Tables("Item").NewRow
                    dr("RentalId") = txtRentalID.Text
                    dr("StyleNumber") = cboGarment.SelectedValue
                    dr("ColourID") = cboColour.SelectedValue
                    dr("ActionID") = Action
                    If cboChest.Enabled = True Then
                        dr("Chest") = cboChest.SelectedValue
                    End If
                    If cboWaist.Enabled = True Then
                        dr("Waist") = cboWaist.SelectedValue

                    End If

                    ds.Tables("Item").Rows.Add(dr)

                    dr2 = ds.Tables("Item").NewRow
                    dr2("RentalId") = txtRentalID.Text
                    dr2("StyleNumber") = cboGarment.SelectedValue
                    dr2("ColourID") = cboColour.SelectedValue
                    dr2("ActionID") = Action
                    If cboChest.Enabled = True Then
                        dr2("Chest") = cboChest.SelectedValue
                    End If
                    If cboWaist.Enabled = True Then
                        dr2("Waist") = cboWaist.SelectedValue

                    End If
                    ds.Tables("Item").Rows.Add(dr2)

                    dr3 = ds.Tables("Item").NewRow
                    dr3("RentalId") = txtRentalID.Text
                    dr3("StyleNumber") = cboGarment.SelectedValue
                    dr3("ColourID") = cboColour.SelectedValue
                    dr3("ActionID") = Action
                    If cboChest.Enabled = True Then
                        dr3("Chest") = cboChest.SelectedValue
                    End If
                    If cboWaist.Enabled = True Then
                        dr3("Waist") = cboWaist.SelectedValue

                    End If
                    ds.Tables("Item").Rows.Add(dr3)

                Catch ex As Exception
                    MessageBox.Show("Failed to Add Row To Dataset" & ex.ToString())

                End Try

I think that Dataset.Row has a method called AddRange(), but im not sure...

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.