Datatable validation

thomas008

Well-known member
Joined
Feb 17, 2009
Messages
54
Location
Belgium
Programming Experience
Beginner
Hi

I have a problem with validating my data.
I load a table from my database into my dataset
in my dataset.vb file i do my validation. When a cells contains an error
i set the columnerrortext. When the a row contains columnerrors i set the rowerrortext. Now my problem is when i add a new row the columnserrors are set but i cant set the rowerror because the row is not added to the colletion yet. So i need the event called after datatable_TableNewRow so i can set the rowerror there. (the reason why i need to set the rowerrors is because i check every row for errors and if none of the rows has an error i allow the users the save the data to the database)
 
No, the event you need is the TableNewRow event.

VB.NET:
Dim WithEvents dtData as New DataTable("RowErrors")

Private Sub frmSlidingForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        AddHandler dtData.TableNewRow, AddressOf HandleNewRow

    End Sub

 Private Sub HandleNewRow(ByVal sender As Object, ByVal e As System.Data.DataTableNewRowEventArgs)

        e.Row.RowError = "No Error"

    End Sub

e will let you access the new row before it has been added to the collection.
 
But i need to know when it is added to the collection? I can add the rowerror and it displays its self on the screen but the row is still not added to the collection because when i click my savebutton i check all rowerrors (= 0 but should be 1 in this case) and if none of my rows contains an error i allow the user to save.
 
This is one of those questions that just doesn't need to be asked because you can easily find out for yourself. How many events does the DataTable class have? Of those, how many could possibly be useful in this case? Just create a DataTable and an event handler for each of those events and then add a row. You'll see which events are raised and you'll know which one to use.
 

Latest posts

Back
Top