Validate csv input

Discussion in 'ASP .Net' started by =?Utf-8?B?bnR1c2VyX21hbkBtc2RuLmNvbQ==?=, Mar 1, 2004.

  1. Howdy

    I'm trying to validate the content of a csv uploaded to a web page. I imported the csv into a DataSet and now I want to loop through all the elements in the DataSet to validate that each is of the appropriate type. After validation I will loop through the records again and write them to a SQL2000 table using a stored procedure.

    My plan for validation is as follows. But I'm not entirely sure how to execute the validations. C# has wonderful built in validation for dropdownlists or textboxes and the like, but I need some help figuring out what to do now that the input does not come from a web control

    Thanks for any help

    --Terr

    foreach (DataRow Rrow in ds.Tables["ImportCSV"].Rows

    foreach(DataColumn Ccolumn in ds.Tables["ImportCSV"].Columns


    if row item EmployeeNumber is not an integer
    Halt loop, display error message
    On row x, the EmployeeNumber "(value)" is not an integer
    Please verify the EmployeeNumber on row x

    if row item First_Name is not an alphanumeric string,
    Halt loop, display error message
    On row x, the First_Name "(value)" is not an alphanumeric string
    Please verify the First_Name on row x

    if row item First_Name has more than 30 characters,
    Halt loop, display error message
    On row x, the First_Name "(value)" has more than 30 characters
    Please verify the First_Name on row x

    ... similar routine for the rest of the columns and rows in the DataSet


    }
    =?Utf-8?B?bnR1c2VyX21hbkBtc2RuLmNvbQ==?=, Mar 1, 2004
    #1
    1. Advertising

  2. =?Utf-8?B?bnR1c2VyX21hbkBtc2RuLmNvbQ==?=

    bulat

    Joined:
    Oct 19, 2009
    Messages:
    1
    Use Flat File Checker Library

    Hi,

    add Flat File Checker library (FlatFileLibrary) to your project (can download source from flat-file.net website); then just create rules required for you validation through the Flat File Checker graphical user interface - to get Xml file that will contains validation rules.

    You can use something something like this to address data errors in your files:

    Code:
    '-----------------------------------------------------------
    
    ' VB.Net Example:
    
    Private WithEvents _files As FlatFileSchema
    
    ' Start validation
    Sub RunValidation()
    ' Use Flat File Checker user interface to create Schema file.
     _files  = New FlatFileSchema(<Schema file path>) 
    _files.RunChecks()
    End Sub
    
    ' Feedback errors when file(s) validation is complete
    Private Sub FileSetValidated(ByVal sender As Object, ByVal e As SchemaValidatedEventArgs) Handles _dataset.Validated
     Dim file As FlatFile
     Dim err As DataError
     For Each file In _files.Files
       For Each err In file.Errors
          ' Feed back error to users here
       Next err
     Next file
    
    End Sub
    '-----------------------------------------------------------
    
    You can also add "on error" action to each data rule. Then only load lines without actions to your database. Or just reject file(s) if there are errors in this file.
    bulat, Oct 19, 2009
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?S01aX3N0YXRl?=

    What layer will I validate a CSV file in?

    =?Utf-8?B?S01aX3N0YXRl?=, Mar 28, 2006, in forum: ASP .Net
    Replies:
    6
    Views:
    436
    Craig Deelsnyder
    Mar 29, 2006
  2. =?Utf-8?B?S01aX3N0YXRl?=

    clarification needed: Which layer to validate CSV file?

    =?Utf-8?B?S01aX3N0YXRl?=, Mar 29, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    389
    sloan
    Mar 29, 2006
  3. Michal Mikolajczyk
    Replies:
    0
    Views:
    630
    Michal Mikolajczyk
    Feb 13, 2004
  4. Skip Montanaro
    Replies:
    0
    Views:
    694
    Skip Montanaro
    Feb 13, 2004
  5. Tintin92
    Replies:
    1
    Views:
    1,673
    Andrew Thompson
    Feb 14, 2007
Loading...

Share This Page