Dobry den. Mam tabulku "cp_polozky_prislusenstvo" v datasete "IspreDataSet". Naplnim ju cez SqlDataAdapter. Zobrazim v datagrid. Chcem zmazať vybrate riadky v tabulke "cp_polozky_prislusenstvo". To nie je problem. Ale ak pridam do tabulky novy riadok a nasledne sa snazim zmazat z nej nejake riadky hadze chybu: Collection was modified; enumeration operation might not execute. Pridanie akceptovanie zmien: cp_polozky_prislusenstvo.acceptchanges() riesi problem ale potom neviem ulozit udaje do databazy cez dataadapter, pretoze nevidi zmeny. Dakujem.
Private Sub Form2_Load(sender As Object, e As EventArgs) Handles MyBase.Load
'nahratie udajov do cp_polozky_prislusenstvo
Dim add2 As SqlDataAdapter
Dim connection As SqlConnection = New SqlConnection(f_hlavny.prip_string)
connection.Open()
add2 = New SqlDataAdapter("SELECT * from cp_polozky_prislusenstvo where cp = 'FI1-0002/01-16' and op = 'D61'", connection)
add2.Fill(ISPREDataSet, "cp_polozky_prislusenstvo")
connection.Close()
DataGridView1.DataSource = IspreDataSet.cp_polozky_prislusenstvo
End Sub
Private Sub pridat_polozku(sender As Object, e As EventArgs) Handles Button1.Click
Dim novy_riadok As DataRow = IspreDataSet.cp_polozky_prislusenstvo.NewRow
novy_riadok("cp") = "FI1-0002/01-16"
novy_riadok("op") = "D61"
IspreDataSet.cp_polozky_prislusenstvo.Rows.Add(novy_riadok)
End Sub
Private Sub zmazat_vsetko(sender As Object, e As EventArgs) Handles zmazat_but.Click
Dim nezmazane = From row In IspreDataSet.cp_polozky_prislusenstvo
Where row.RowState <> DataRowState.Deleted
Select row
Dim toDelete = From row In nezmazane
Where row.Item("kr_zar") = 1 And row.Item("p") = "p3"
Select row
For Each row In toDelete
row.Delete()
Next
End Sub
Private Sub Ulož_Click(sender As Object, e As EventArgs) Handles Ulož.Click
Cp_polozky_prislusenstvoTableAdapter1.Update(IspreDataSet.cp_polozky_prislusenstvo)
End Sub
|