DataRow constructor not available when writing DataSet extension?

I am trying to write a couple of extensions to convert UniDataSets and UniRecords to DataSet and DataRow , but when I try to compile, I get the following error.

'System.Data.DataRow.DataRow (System.Data.DataRowBuilder)' is unavailable due to the level of protection

Is there a way to fix this, or should I abandon this approach and come to it differently?

  using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Data; using IBMU2.UODOTNET; namespace Extentions { public static class UniDataExtentions { public static System.Data.DataSet ImportUniDataSet(this System.Data.DataSet dataSet, IBMU2.UODOTNET.UniDataSet uniDataSet) { foreach (UniRecord uniRecord in uniDataSet) { DataRow dataRow = new DataRow(); dataRow.ImportUniRecord(uniRecord); dataSet.Tables[0].ImportRow(dataRow); } return dataSet; } public static void ImportUniRecord(this System.Data.DataRow dataRow, IBMU2.UODOTNET.UniRecord uniRecord) { int fieldCount = uniRecord.Record.Dcount(); // ADD COLUMS dataRow.Table.Columns.AddRange(new DataColumn[fieldCount]); // ADD ROW for (int x = 1; x < fieldCount; x++) { string stringValue = uniRecord.Record.Extract(x).StringValue; dataRow[x] = stringValue; } } } } 
+6
source share
2 answers

It doesn’t matter if it is used in an extension method or any method. The DataRow constructor is not public. You must use the DataTable.NewRow() method to create a new DataRow .

He will use the schema information from the data table to create a row that matches it. If you just tried to use the constructor on it, then the object would have no idea which circuit to use.

+18
source

I tried a simpler approach, however it is intended for several lines and can be applied to one line:

 //Declare a variable for multiple rows DataRow[] rows = null; //get some data in a DataTable named table //Select specific data from DataTable named table rows = table.Select("column = 'ColumnValue'"); //Read the value in a variable from the row string ColumnValue = rows[0]["column"].ToString(); 

hope this helps ...

0
source

All Articles