Solved

Help with saving data added in DatagridView

Posted on 2016-10-02
1
68 Views
Last Modified: 2016-10-03
Hello,

How do I modify the code below to save new records entered in a DataGridView?, I'm able to save changes made to existing rows but can not save data entered in new rows.

 Private Sub Button4_Click(sender As System.Object, e As System.EventArgs) Handles Button4.Click
        Dim GGB As String
        GGB = "'" & ComboBox1.SelectedItem & "'"
        Dim SearchCriteriaZ As String = "COUNTRY IN (" & GGB & ")"
        xmlPath1 = System.IO.Path.Combine(Application.StartupPath + "\file1.xml")  'grid1
        dtsetcol1.Clear()
        dtsetcol1.ReadXml(xmlPath1)

        Dim DVA As New DataView(dtsetcol1.Tables(0), SearchCriteriaZ, Nothing, DataViewRowState.CurrentRows)
        FilteredDTA = DVA.ToTable
End Sub

 Private Sub Save_Click(sender As System.Object, e As System.EventArgs) Handles Save.Click

          FilteredDTA.WriteXml(Application.StartupPath + "\file1.xml")
        MsgBox("Records saved")
    End Sub

Thanks,

Victor
0
Comment
Question by:vcharles
1 Comment
 
LVL 29

Accepted Solution

by:
Randy Downs earned 500 total points
ID: 41826393
Try something like this

  

    ' Add one row:
    dataRow = dataTable.NewRow()
    dataRow("dataColumn") = "World"
    dataTable.Rows.Add(dataRow)

    ' Set the RowStateFilter to display only Added and modified rows.
    dataView.RowStateFilter = _
    DataViewRowState.Added Or DataViewRowState.ModifiedCurrent

Open in new window

0

Featured Post

Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

860 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question