none
Dataview.ToTable RRS feed

  • Question

  • I have a datatable reportDT in which I want to find a particular row, If I find the row I want to change a column value and then save the row.

     

     

    DataView view = reportDT.DefaultView;

    view.RowFilter = "Invoice ='123'";

     

    if (view.ToTable().Rows.Count != 0)

    {

    I do not know how to change the column in reportDT;

    }

     

    Any help would be appreciated.

     

     

    Tuesday, April 1, 2008 5:18 PM

Answers

  •  

    Well, which number is causing the out of range?  How many rows are returned by the select?  You may want to add:

     

    if (dra != null and dra.Length > 0)

     

     

    Hope this helps..

     

     

    Wednesday, April 2, 2008 12:22 AM

All replies

  •  

    DataRowArray dra = reportDT.Select("Invoice = 123");

    if (dra != null)

    {

    dra[0]["MyColumn"] = newValue;

    }

     

    The value is automatically updated in reportDT.

    Tuesday, April 1, 2008 7:12 PM
  • Thanks for helping - I seem to have some difficulty with this:

     

    DataRow [] dra = reportDT.Select(strSelection);

    if (dra != null)

    {

    dra[0][5] = 99;/// this give an error out of range

    }

     

    Wednesday, April 2, 2008 12:14 AM
  •  

    Well, which number is causing the out of range?  How many rows are returned by the select?  You may want to add:

     

    if (dra != null and dra.Length > 0)

     

     

    Hope this helps..

     

     

    Wednesday, April 2, 2008 12:22 AM
  • Thanks again : this is the code i used:

     

    //find a record in a table - change value - update table

    DataRow [] dra = reportDT.Select(strSelection);

     

    if (dra.Length > 0)

    {

    //assign values

    dra[0].AcceptChanges();

    }

    else

    {

    //add the row

    DataRow ndr = this.reportDT.NewRow();

    //assign new values

    this.reportDT.Rows.Add(ndr);

    }

     

     

    Wednesday, April 2, 2008 3:42 PM