Solved

select rows with errors

Posted on 2004-10-26
229 Views
Last Modified: 2006-11-17
How can I fill a datagrid with just the rows from a datatable where haserrors = true?  Also, how can I get a count of the rows that have errors in a datatable?
0
Question by:km1039
    10 Comments
     

    Author Comment

    by:km1039
    Without looping through the rows collection for the count.
    0
     
    LVL 18

    Expert Comment

    by:tusharashah
    You can display such records like following:

    DataView DataView1 = new DataView( DataSet1.Tables[0] );
    DataView1.RowFilter = "haserrors='true'";
    // DataView1.Count should give you all such records..
    DataGrid1.DataSource = DataView1;
    DataGrid1.DataBind();

    -tushar
    0
     
    LVL 28

    Accepted Solution

    by:
    Hi km1039,

    i don't think so
    you can use this

    DataTable dt_copy = your_dataTable.Clone();
    foreach ( DataRow dr in your_dataTable.Rows )
    {
        if ( dr.HasErrors )
        {
            dt.Rows.Add ( dr.ItemArray );
        }
    }


    Regards!
    B..M
    0
     

    Author Comment

    by:km1039
    that will work... thanks.
    0
     

    Author Comment

    by:km1039
    Nevermind, it didnt work.  

    So the only way to do it is to loop through the rows?
    0
     
    LVL 18

    Expert Comment

    by:tusharashah
    If DataView1.Count dose not provide correct count then creat DataView like following:

    DataView DataView1 = new DataView( DataSet1.Tables[0],"haserrors='true'","", System.Data.DataViewRowState.CurrentRows )

    -tushar
    0
     

    Author Comment

    by:km1039
    Still no luck.  The "haserrors='true'" is the problem.  It has to be a column in the datatable.
    0
     
    LVL 18

    Expert Comment

    by:tusharashah
    Oh in that case.. the way --> The B..M

    -tushar
    0
     

    Author Comment

    by:km1039
    Thanks mmarinov.
    0
     
    LVL 28

    Expert Comment

    by:mmarinov
    km1039,

    No problem, you are welcome
    sorry, again for using you question for different purposes

    Regards!
    B..M
    0

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
    I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
    Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

    913 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

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now