How to Edit a row in the datatable

First you need to find a row with id == 2 then change the name so: foreach(DataRow dr in table.Rows) // search whole table { if(dr[“Product_id”] == 2) // if id==2 { dr[“Product_name”] = “cde”; //change the name //break; break or not depending on you } } You could also try these solutions: table.Rows[1][“Product_name”] = … Read more

How to access a specific cell value of a datatable

If you need a weak reference to the cell value: object field = d.Rows[0][3] or object field = d.Rows[0].ItemArray[3] Should do it If you need a strongly typed reference (string in your case) you can use the DataRowExtensions.Field extension method: string field = d.Rows[0].Field<string>(3); (make sure System.Data is in listed in the namespaces in this … Read more

Ajax update doesn’t work, when using filter on p:dataTable

After updating datatable you have to invoke it’s client side filter() method. <p:dataTable widgetVar=”dataTableWidgetVar” id=”dataTable” var=”row” value=”#{bean.value}” filteredValue=”#{bean.filteredValue}” paginator=”true” rows=”25″ paginatorPosition=”bottom” rowKey=”${row.id}” editable=”true”> <p:commandButton value=”Save” actionListener=”#{bean.save}” update=”:form” oncomplete=”PF(‘dataTableWidgetVar’).filter()”/> For PrimeFaces versions older than 5, you should use <p:commandButton value=”Save” actionListener=”#{bean.save}” update=”:form” oncomplete=”dataTableWidgetVar.filter()”/>

Find a value in DataTable

A DataTable or DataSet object will have a Select Method that will return a DataRow array of results based on the query passed in as it’s parameter. Looking at your requirement your filterexpression will have to be somewhat general to make this work. myDataTable.Select(“columnName1 like ‘%” + value + “%'”);

Convert DataTable to CSV stream

You can just write something quickly yourself: public static class Extensions { public static string ToCSV(this DataTable table) { var result = new StringBuilder(); for (int i = 0; i < table.Columns.Count; i++) { result.Append(table.Columns[i].ColumnName); result.Append(i == table.Columns.Count – 1 ? “\n” : “,”); } foreach (DataRow row in table.Rows) { for (int i = … Read more

tech