Returning DataTables in WCF/.NET

For anyone having similar problems, I have solved my issue. It was several-fold. As Darren suggested and Paul backed up, the Max..Size properties in the configuration needed to be enlarged. The SvcTraceViewer utility helped in determining this, but it still does not always give the most helpful error messages. It also appears that when the … Read more

SqlBulkCopy – The given value of type String from the data source cannot be converted to type money of the specified target column

For the people stumbling across this question and getting a similar error message in regards to an nvarchar instead of money: The given value of type String from the data source cannot be converted to type nvarchar of the specified target column. This could be caused by a too-short column. For example, if your column … Read more

How do you Sort a DataTable given column and direction?

I assume “direction” is “ASC” or “DESC” and dt contains a column named “colName” public static DataTable resort(DataTable dt, string colName, string direction) { DataTable dtOut = null; dt.DefaultView.Sort = colName + ” ” + direction; dtOut = dt.DefaultView.ToTable(); return dtOut; } OR without creating dtOut public static DataTable resort(DataTable dt, string colName, string direction) … Read more

How to change DataTable columns order

Try to use the DataColumn.SetOrdinal method. For example: dataTable.Columns[“Qty”].SetOrdinal(0); dataTable.Columns[“Unit”].SetOrdinal(1); UPDATE: This answer received much more attention than I expected. To avoid confusion and make it easier to use I decided to create an extension method for column ordering in DataTable: Extension method: public static class DataTableExtensions { public static void SetColumnsOrder(this DataTable table, params … Read more

Can’t bind to ‘dataSource’ since it isn’t a known property of ‘table’

Remember to add MatTableModule in your app.module’s imports i.e. In Angular 9+ import { MatTableModule } from ‘@angular/material/table’ @NgModule({ imports: [ // … MatTableModule // … ] }) Less than Angular 9 import { MatTableModule } from ‘@angular/material’ @NgModule({ imports: [ // … MatTableModule // … ] })

Dynamically generate h:column based on list of hashmaps

Is it possible to bind a List of HashMaps to the jsf component h:dataTable? That’s only possible if you generate the necessary <h:column> tags with a view build time tag such as JSTL <c:forEach>. Here’s a concrete kickoff example, assuming that your environment supports EL 2.2: <h:dataTable value=”#{bean.listOfMaps}” var=”map”> <c:forEach items=”#{bean.listOfMaps[0].keySet().toArray()}” var=”key”> <h:column> #{map[key]} </h:column> … Read more

Convert DataTable to IEnumerable

There’s also a DataSetExtension method called “AsEnumerable()” (in System.Data) that takes a DataTable and returns an Enumerable. See the MSDN doc for more details, but it’s basically as easy as: dataTable.AsEnumerable() The downside is that it’s enumerating DataRow, not your custom class. A “Select()” LINQ call could convert the row data, however: private IEnumerable<TankReading> ConvertToTankReadings(DataTable … Read more

How do I loop through rows with a data reader in C#?

That’s the way the DataReader works, it’s designed to read the database rows one at a time. while(reader.Read()) { var value1 = reader.GetValue(0); // On first iteration will be hello var value2 = reader.GetValue(1); // On first iteration will be hello2 var value3 = reader.GetValue(2); // On first iteration will be hello3 }