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

DataTable already belongs to another DataSet

Like the other responses point out, the error you’re seeing is because the DataTable you’re attempting to add to a DataSet is already a part of a different DataSet. One solution is to Copy the DataTable and assign the copy to the other DataSet. dtCopy = dataTable.Copy() ds.Tables.Add(dtCopy) The copied DataTable will have the structure … Read more

ReadOnlyException DataTable DataRow “Column X is read only.”

using DataAdapter.Fill does not load the database schema, which includes whether a column is a primary key or not, and whether a column is read-only or not. To load the database schema, use DataAdapter.FillSchema, but then that’s not your questions. using DataReader to fill a table loads the schema. So, the index column is read-only … 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 to get list of one column values from DataTable?

You can use Linq to DataTable: var ids = dt.AsEnumerable().Select(r => r.Field<int>(“id”)).ToList(); UPDATE: Without Linq List<int> ids = new List<int>(dt.Rows.Count); foreach(DataRow row in dt.Rows) ids.Add((int)row[“id”]); Note for efficiency it’s better to use row[index] instead of row[columnName]. First one just gets column by index from columns array. Latter gets column index from internal dictionary which maps … 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 }

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)