Does anyone know how to do this?
I'm using EPPlus in .Net and have created a pivot table with 2 row fields and one summary datafield:
Dim Pivot As OfficeOpenXml.Table.PivotTable.ExcelPivotTable
Pivot = wksPivot.PivotTables.Add(wksPivot.Cells("A1"), Datarange, "pName")
Pivot.RowFields.Add(Pivot.Fields("Fld1")).Sort = Table.PivotTable.eSortType.Ascending
Pivot.RowFields.Add(Pivot.Fields("Fld2")).Sort = Table.PivotTable.eSortType.Ascending
Dim dtaFld As OfficeOpenXml.Table.PivotTable.ExcelPivotTableDataField
dtaFld = Pivot.DataFields.Add(Pivot.Fields("XYZ"))
dtaFld.Function = Table.PivotTable.DataFieldFunctions.Sum
Everything works great, but I want to have the Pivot Table start off as collapsed when the user opens the workbook (In excel, when you're creating the pivot table, you can right-click in the data element and select "Expand / Collapse" > "Collapse Entire Field"
Hot can I do this via code?? (And I'm willing to use direct OpenXML if EPPlus doesn't support this yet...)
ALSO, is there a way to delete out the Raw data from the workbook so that the pivot table still works? i've tried and when I open the workbook, my pivot table is blank? - My current logic has led me to this question... Any thoughts??
(I do know I wrote this question in VB. but I added both the C# & VB tags to this question - I'm comfortable with code in either language - Thanks!!)
Could make it xlsm and add vba to it. This is probably the worst answer to this solution but it achives full collapse. I have provided a working example, just copy past into a new console app. add the epplus dependency, "F5".
modified/taken from http://epplus.codeplex.com/SourceControl/latest#SampleApp/Sample15.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using OfficeOpenXml.Table;
using OfficeOpenXml.Table.PivotTable;
using OfficeOpenXml;
using System.IO;
namespace pTable
{
class Program
{
static void Main(string[] args)
{
//ExcelPackage _pck = new ExcelPackage();
Directory.CreateDirectory(string.Format("Test"));
//ExcelPackage _pck = new ExcelPackage(new FileInfo("Test\\Worksheet.xlsx"));
ExcelPackage _pck = new ExcelPackage(new FileInfo("Test\\Worksheet.xlsm"));
var wsPivot1 = _pck.Workbook.Worksheets.Add("Rows-Data on columns");
var ws = _pck.Workbook.Worksheets.Add("Data");
ws.Cells["K1"].Value = "Item";
ws.Cells["L1"].Value = "Category";
ws.Cells["M1"].Value = "Stock";
ws.Cells["N1"].Value = "Price";
ws.Cells["O1"].Value = "Date for grouping";
ws.Cells["K2"].Value = "Crowbar";
ws.Cells["L2"].Value = "Hardware";
ws.Cells["M2"].Value = 12;
ws.Cells["N2"].Value = 85.2;
ws.Cells["O2"].Value = new DateTime(2010, 1, 31);
ws.Cells["K3"].Value = "Crowbar";
ws.Cells["L3"].Value = "Hardware";
ws.Cells["M3"].Value = 15;
ws.Cells["N3"].Value = 12.2;
ws.Cells["O3"].Value = new DateTime(2010, 2, 28);
ws.Cells["K4"].Value = "Hammer";
ws.Cells["L4"].Value = "Hardware";
ws.Cells["M4"].Value = 550;
ws.Cells["N4"].Value = 72.7;
ws.Cells["O4"].Value = new DateTime(2010, 3, 31);
ws.Cells["K5"].Value = "Hammer";
ws.Cells["L5"].Value = "Hardware";
ws.Cells["M5"].Value = 120;
ws.Cells["N5"].Value = 11.3;
ws.Cells["O5"].Value = new DateTime(2010, 4, 30);
ws.Cells["K6"].Value = "Crowbar";
ws.Cells["L6"].Value = "Hardware";
ws.Cells["M6"].Value = 120;
ws.Cells["N6"].Value = 173.2;
ws.Cells["O6"].Value = new DateTime(2010, 5, 31);
ws.Cells["K7"].Value = "Hammer";
ws.Cells["L7"].Value = "Hardware";
ws.Cells["M7"].Value = 1;
ws.Cells["N7"].Value = 4.2;
ws.Cells["O7"].Value = new DateTime(2010, 6, 30);
ws.Cells["K8"].Value = "Saw";
ws.Cells["L8"].Value = "Hardware";
ws.Cells["M8"].Value = 4;
ws.Cells["N8"].Value = 33.12;
ws.Cells["O8"].Value = new DateTime(2010, 6, 28);
ws.Cells["K9"].Value = "Screwdriver";
ws.Cells["L9"].Value = "Hardware";
ws.Cells["M9"].Value = 1200;
ws.Cells["N9"].Value = 45.2;
ws.Cells["O9"].Value = new DateTime(2010, 8, 31);
ws.Cells["K10"].Value = "Apple";
ws.Cells["L10"].Value = "Groceries";
ws.Cells["M10"].Value = 807;
ws.Cells["N10"].Value = 1.2;
ws.Cells["O10"].Value = new DateTime(2010, 9, 30);
ws.Cells["K11"].Value = "Butter";
ws.Cells["L11"].Value = "Groceries";
ws.Cells["M11"].Value = 52;
ws.Cells["N11"].Value = 7.2;
ws.Cells["O11"].Value = new DateTime(2010, 10, 31);
ws.Cells["O2:O11"].Style.Numberformat.Format = "yyyy-MM-dd";
var pt = wsPivot1.PivotTables.Add(wsPivot1.Cells["A1"], ws.Cells["K1:N11"], "Pivottable1");
pt.Compact = true;
pt.CompactData = true;
pt.GrandTotalCaption = "Total amount";
pt.RowFields.Add(pt.Fields[1]);
pt.RowFields.Add(pt.Fields[0]);
pt.DataFields.Add(pt.Fields[3]);
pt.DataFields.Add(pt.Fields[2]);
pt.DataFields[0].Function = DataFieldFunctions.Product;
pt.DataOnRows = false;
_pck.Workbook.CreateVBAProject();
var sb = new StringBuilder();
sb.AppendLine("Private Sub Workbook_Open()");
sb.AppendLine(" Range(\"A1\").Select");
sb.AppendLine(" ActiveSheet.PivotTables(\"Pivottable1\").PivotFields(\"Category\").PivotItems(\"Hardware\").ShowDetail = False");
sb.AppendLine("End Sub");
_pck.Workbook.CodeModule.Code = sb.ToString();
_pck.Save();
}
}
}
Using EPPlus you could try something like (Taken from this SO post):
(from pf in pivot.Fields
select pf).ToList().ForEach(f =>
{
f.Compact = false;
f.Outline = false;
});
or perhaps more simply, doesn't something like the following work?
pvtTable.Compact = False
pvtTable.CompactData = False
pvtTable.Outline = False
pvtTable.OutlineData = False
pvtTable.ShowDrill = True
Also look at this SO post detailing a nice reverse engineer method for seeing how excel achieves 'things'.
P.S. Can't help you with your other 'also' question sorry.
Related
This is the code which i used to generate pie chart . I need to add percentage value to piechart series.Tries few ways but did not find solution.I have attached my working code output image and expected image .
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms.DataVisualization.Charting;
using System.Diagnostics;
using System.Drawing;
using System.Data;
using System.Xml;
using System.Collections;
public bool GetPieChart(string XML , string Path)
{
try
{
// create chart instance
var chart = new Chart();
// set chart height and width
chart.Height = 500;
chart.Width = 600;
// Add legend to chart
chart.Legends.Add(new Legend() { Name = "Legend" });
chart.Legends[0].Font = new Font("Verdana", 10);
chart.Legends[0].Docking = Docking.Bottom;
ArrayList xAxisData = new ArrayList();
ArrayList yAxisData = new ArrayList();
XmlDocument xml = new XmlDocument();
xml.LoadXml(XML);
XmlNodeList multiLine = xml.DocumentElement.SelectNodes("/Report/PieChart/series");
// Set Chart Title
string title = xml.SelectSingleNode("/Report").Attributes["Name"].Value.ToString();
chart.Titles.Add(title);
chart.Titles[0].Font = new Font("Verdana", 12);
// Set chart properties
var chartArea = new ChartArea();
chart.ChartAreas.Add(chartArea);
Series series;
// Add data to the chart
foreach (XmlNode seriesNode in multiLine)
{
xAxisData.Clear();
yAxisData.Clear();
series = new Series();
string seriesName = seriesNode.Attributes["name"].Value.ToString();
XmlNodeList detailsList = seriesNode.SelectNodes("datapoint");
foreach (XmlNode detailNode in detailsList)
{
xAxisData.Add(detailNode.Attributes["Label"].Value.ToString());
int value;
string st = detailNode.Attributes["value"].Value.ToString();
int.TryParse(st, out value);
yAxisData.Add(value);
}
// set series properties
series.Name = seriesName;
series.ChartType = SeriesChartType.Pie;
chart.Series.Add(series);
chart.Series[seriesName].Points.DataBindXY(xAxisData, yAxisData);
chart.Series[seriesName]["PieLabelStyle"] = "Outside";
chart.Series[seriesName]["PieLineColor"] = "Black";
}
chart.SaveImage(Path, ChartImageFormat.Jpeg);
}
catch (Exception ex)
{
}
return true;
}
This is the out put from this code
This is what i expect
Guys need your help to do that ?
foreach (DataPoint p in YourChart.Series["YourSeriesName"].Points)
{
p.Label = "#PERCENT\n#VALX";
}
Finally found solution. Now works well.
chart.Series[seriesName].XValueMember = "Name";
chart.Series[seriesName].YValueMembers = "Count";
chart.Series[seriesName].IsValueShownAsLabel = true;
escape percentage sign with double percentage char. look for the sample below
Chart1.Series.Add(series);
Series series1 = Chart1.Series[0];
series1.Points.DataBindXY(xValues, yValues);
Title ti = new Title()
ti.TextStyle = TextStyle.Emboss;
ti.Text = ((yValues[0] / 100) * 100) + #"%%";//double Percentage sign
ti.Font = new Font("Times New Roman", 40, FontStyle.Bold);
ti.Position.X = 50;
ti.Position.Y = 50;
Chart1.Titles.Add(ti);
this maybe help. This code is for a Pie Chart with percentage inside the Pie and labels(strings) in the legends: Where datosSeries = List
string[] labels = datosSeries.Select(o => o.Week).ToArray();
float[] data = datosSeries.Select(o => o.ProfitSerie).ToArray();
chart2.Series.Add("Series1");
chart2.Series[0].Points.DataBindXY(labels, data);
chart2.Series[0].ChartType = SeriesChartType.Pie;
chart2.Series[0]["PieLabelStyle"] = "Outside";
chart2.Series[0].BorderWidth = 1;
chart2.Series[0].BorderColor = System.Drawing.Color.FromArgb(26, 59, 105);
chart2.Series[0].Label = "#PERCENT{P2}";
chart2.Legends.Add(new Legend("Default"));
// Add Color column
LegendCellColumn firstColumn = new LegendCellColumn();
firstColumn.ColumnType = LegendCellColumnType.SeriesSymbol;
firstColumn.HeaderText = "";
chart2.Legends["Default"].CellColumns.Add(firstColumn);
// Add name cell column
LegendCellColumn percentColumn = new LegendCellColumn();
percentColumn.Text = "#VALX";
percentColumn.HeaderText = "Tipo de Gastos";
percentColumn.Name = "nameColumn";
chart2.Legends["Default"].CellColumns.Add(percentColumn);
//Format the legend
chart2.Legends["Default"].LegendStyle = LegendStyle.Table;
chart2.Legends["Default"].TableStyle = LegendTableStyle.Tall;
chart2.Legends["Default"].DockedToChartArea = "ChartArea1";
chart2.Legends["Default"].IsDockedInsideChartArea = false;
chart2.Legends["Default"].Docking = Docking.Bottom;
I am developing a program that has the feature to dynamically create DocX files. As the title suggests, I am having a problem inserting images into a DocX file. One of the issues, as I see it, is that I am using C# 2.0. (When answering this question, I would like to stress that I do not wish to switch to C# 3.0, so please do not try to persuade me.)
I have taken a look at the MSDN article at http://msdn.microsoft.com/en-us/library/office/bb497430.aspx, but when I converted the C# 3.0 code that MSDN uses to C# 2.0, I get a document that does not open, and it gives me the error: "The file Testing.docx cannot be opened because there are problems with the contents," and "No error detail available."
Here is my code:
ImagePart ip_Part;
WordprocessingDocument wpd_Doc = WordprocessingDocument.Create("C:\\Convert\\Testing.docx", WordprocessingDocumentType.Document);
public Testing()
{
wpd_Doc.AddMainDocumentPart();
wpd_Doc.MainDocumentPart.Document = new Document();
wpd_Doc.MainDocumentPart.Document.Body = new Body();
ip_Part = wpd_Doc.MainDocumentPart.AddImagePart(ImagePartType.Png);
System.IO.FileStream fs_Stream = new System.IO.FileStream("image.png", System.IO.FileMode.Open);
ip_Part.FeedData(fs_Stream);
AddImageToBody("image.png", wpd_Doc.MainDocumentPart.GetIdOfPart(ip_Part));
AppendText("Here is a test bulleted list:");
wpd_Doc.MainDocumentPart.Document.Save();
//Close the document.
wpd_Doc.Close();
}
private void AddImageToBody(string s_ImagePath, string s_RelationshipId)
{
//OpenXmlElement oxe_Element = new Numbering();
Drawing d_Drawing = new Drawing();
DrawWord.Inline i_Inline = new DrawWord.Inline();
DrawWord.Extent e_Extent = new DrawWord.Extent();
e_Extent.Cx = 600075; //63px / 96dpi * 914400
e_Extent.Cy = 600075; //63px / 96dpi * 914400
i_Inline.Extent = e_Extent;
DrawWord.DocProperties dp_Prop = new DrawWord.DocProperties();
//dp_Prop.Id = uint.Parse(System.DateTime.Now.Minute.ToString() + System.DateTime.Now.Second.ToString() + System.DateTime.Now.Millisecond.ToString());
dp_Prop.Id = 1;
dp_Prop.Name = "Picture 1";
dp_Prop.Description = "An automated image.";
i_Inline.DocProperties = dp_Prop;
DrawWord.NonVisualGraphicFrameDrawingProperties nvgfdp_Prop = new DrawWord.NonVisualGraphicFrameDrawingProperties();
Draw.GraphicFrameLocks gfl_Locks = new Draw.GraphicFrameLocks();
gfl_Locks.NoChangeAspect = true;
nvgfdp_Prop.GraphicFrameLocks = gfl_Locks;
i_Inline.NonVisualGraphicFrameDrawingProperties = nvgfdp_Prop;
Draw.Graphic g_Graphic = new Draw.Graphic();
Draw.GraphicData gd_Data = new DocumentFormat.OpenXml.Drawing.GraphicData();
gd_Data.Uri = DateTime.Now.Minute.ToString() + DateTime.Now.Second.ToString() + DateTime.Now.Millisecond.ToString();
DrawPic.Picture p_Pic = new DrawPic.Picture();
DrawPic.NonVisualPictureProperties nvpp_Prop = new DrawPic.NonVisualPictureProperties();
DrawPic.NonVisualDrawingProperties nvdp_Prop = new DrawPic.NonVisualDrawingProperties();
nvdp_Prop.Id = uint.Parse(System.DateTime.Now.Minute.ToString() + System.DateTime.Now.Second.ToString() + System.DateTime.Now.Millisecond.ToString());
//nvdp_Prop.Name = s_ImagePath;
nvdp_Prop.Name = "New_Image.png";
nvpp_Prop.NonVisualDrawingProperties = nvdp_Prop;
DrawPic.NonVisualPictureDrawingProperties nvpdp_Prop = new DrawPic.NonVisualPictureDrawingProperties();
nvpp_Prop.NonVisualPictureDrawingProperties = nvpdp_Prop;
p_Pic.NonVisualPictureProperties = nvpp_Prop;
DrawPic.BlipFill bf_Fill = new DrawPic.BlipFill();
Draw.Blip b_Blip = new Draw.Blip();
Draw.ExtensionList el_List = new Draw.ExtensionList();
Draw.BlipExtension be_Extension = new Draw.BlipExtension();
be_Extension.Uri = "{28A0092B-C50C-407E-A947-70E740481C1C}";
el_List.Append(be_Extension);
b_Blip.Append(el_List);
b_Blip.Embed = s_RelationshipId;
b_Blip.CompressionState = Draw.BlipCompressionValues.Print;
bf_Fill.Blip = b_Blip;
Draw.Stretch s_Stretch = new Draw.Stretch();
Draw.FillRectangle fr_Rect = new Draw.FillRectangle();
s_Stretch.FillRectangle = fr_Rect;
bf_Fill.Append(s_Stretch);
p_Pic.BlipFill = bf_Fill;
DrawPic.ShapeProperties sp_Prop = new DrawPic.ShapeProperties();
Draw.Transform2D t2d_Transform = new Draw.Transform2D();
Draw.Offset o_Offset = new Draw.Offset();
o_Offset.X = 0;
o_Offset.Y = 0;
t2d_Transform.Offset = o_Offset;
Draw.Extents e_Extents = new Draw.Extents();
e_Extents.Cx = 600075; //63px / 96dpi * 914400
e_Extents.Cy = 600075; //63px / 96dpi * 914400
t2d_Transform.Extents = e_Extents;
sp_Prop.Transform2D = t2d_Transform;
Draw.PresetGeometry pg_Geom = new Draw.PresetGeometry();
Draw.AdjustValueList avl_List = new Draw.AdjustValueList();
pg_Geom.AdjustValueList = avl_List;
pg_Geom.Preset = Draw.ShapeTypeValues.Rectangle;
sp_Prop.Append(pg_Geom);
p_Pic.ShapeProperties = sp_Prop;
gd_Data.Append(p_Pic);
g_Graphic.GraphicData = gd_Data;
i_Inline.Graphic = g_Graphic;
d_Drawing.Inline = i_Inline;
//oxe_Element.Append(d_Drawing);
//Run r_Run = new Run(d_Drawing);
wpd_Doc.MainDocumentPart.Document.Body.AppendChild(new Paragraph(new Run(d_Drawing)));
}
(The variable names are bad, but this was just a test program, so I did not spend too much time. Also, I have the lines spaced to mimic the Xml format that MSDN had in its example. If I could use the C# 3.0 syntax, I would, but I am using Visual Studio 2005.)
I have found the answer. Surprisingly, I did not find this webpage--because it was some Google pages down with some odd keyword searching--that completely worked: http://blog.stuartwhiteford.com/?p=33. Though it is written with Collection Initializations, I was able to change them to fit C# 2.0 standards.
Is it possible to change CreationDateTime, SentDateTime, etc.????
I`m tring to create/update message. All run fine, but i need to set field ItemType.CreateDateTime with my values (eg. I need to create message that has time creation not today, but year ego).
I have next code:
//Update created item
ItemIdType itemId = new ItemIdType();
itemId.Id = savedMessageId;
itemId.ChangeKey = savedMessageChangeKey;
ItemType setCreateDT = new ItemType();
setCreateDT.DateTimeCreated = new System.DateTime(2000, 10, 10, 12, 12, 12);
setCreateDT.DateTimeCreatedSpecified = true;
SetItemFieldType setItemField = new SetItemFieldType();
setItemField.Item = new PathToUnindexedFieldType();
(setItemField.Item as PathToUnindexedFieldType).FieldURI = UnindexedFieldURIType.itemDateTimeCreated;
setItemField.Item1 = setCreateDT;
UpdateItemType request = new UpdateItemType();
request.ItemChanges = new ItemChangeType[1] { new ItemChangeType() };
request.ItemChanges[0].Item = itemId;
request.ItemChanges[0].Updates = new ItemChangeDescriptionType[1];
request.ItemChanges[0].Updates[0] = setItemField;
request.MessageDisposition = MessageDispositionType.SaveOnly;
request.MessageDispositionSpecified = true;
UpdateItemResponseType updateItemResponse = m_mailbox.UpdateItem(request);
That request return Error: "Set action is invalid for property."
If im tring to change Subject, all run OK.
[UPDATE]
Found next solution, but it doesn`t work.
There is using extended properties and their ids.
PathToExtendedFieldType q = new PathToExtendedFieldType();
q.PropertyId = 3590; //DeliveryTime
q.PropertyType = MapiPropertyTypeType.SystemTime;
q.PropertyIdSpecified = true;
newItem.ExtendedProperty[0] = new ExtendedPropertyType();
newItem.ExtendedProperty[0].ExtendedFieldURI = q;
newItem.ExtendedProperty[0].ExtendedFieldURI.DistinguishedPropertySetIdSpecified = true;
newItem.ExtendedProperty[0].Item = new System.DateTime(2013, 5, 5, 5, 5, 5).ToString("yyyy-MM-ddTHH:mm:ssZ");
...
CreateItemResponseType createItemResponse = m_mailbox.CreateItem(createItemType);
It works fine, but i don`t see any changes..
Second solution is correct, but there are some mistakes.
1) It's better to get access to properties by PropertyTag.
2) You should only set up PropertyTag and PropertyType.
Here is working code:
ItemType newItem = xmlParser.LoadItem(); //info for newItem takes from xml
newItem.ExtendedProperty = new ExtendedPropertyType[1];
PathToExtendedFieldType q = new PathToExtendedFieldType();
q.PropertyTag = "3590"; //DeliveryTime
q.PropertyType = MapiPropertyTypeType.SystemTime;
newItem.ExtendedProperty[0] = new ExtendedPropertyType();
newItem.ExtendedProperty[0].ExtendedFieldURI = q;
newItem.ExtendedProperty[0].Item = new System.DateTime(2014, 5, 5, 5, 5, 5).ToString("yyyy-MM-ddTHH:mm:ssZ");
I am using QLNet for american option pricing, but it doesn't work.
i have posted my question on Quantlib forum
my code:
todaysDate & settlementdate = 2012-12-18, maturity = 2013-01-18,
Calendar calendar = new TARGET();
Settings.setEvaluationDate(TodaysDate);
DayCounter dayCounter = new Actual365Fixed();
Handle<Quote> underlyingH = new Handle<Quote>(new SimpleQuote(100));
var flatTermStructure = new Handle<YieldTermStructure>(new FlatForward(SettlementDate, 0.08, dayCounter));
var flatDividendTS = new Handle<YieldTermStructure>(new FlatForward(SettlementDate, 0, dayCounter));
var flatVolTS = new Handle<BlackVolTermStructure>(new BlackConstantVol(SettlementDate, calendar, 0.2, dayCounter));
StrikedTypePayoff payoff = new PlainVanillaPayoff(Call, 101);
var bsmProcess = new BlackScholesMertonProcess(underlyingH, flatDividendTS, flatTermStructure, flatVolTS);
Exercise exerciseEngine = exerciseEngine = new AmericanExercise(SettlementDate, Maturity);
VanillaOption optionEngine = new VanillaOption(payoff, exerciseEngine);
optionEngine.setPricingEngine(new BinomialVanillaEngine<CoxRossRubinstein>(bsmProcess, 801));
//error:
optionEngine.impliedVolatility(optionEngine.NPV(), bsmProcess, 1.0e-4, 100, 1.0e-7, 4.0);
underlying = 100, k=101, i=0.08, vol=0.2,div=0,
todaysDate & settlementdate = 2012-12-18, maturity = 2013-01-18,
In VanillaOption.cs, the code of case Exercise.Type.American is uncomment;
The error message is: An item with the same key has already been added.
at line 111 (results.additionalResults.Add priceCurve, prices_) in FDStepConditionEngine.cs
Thanks for kindly help.
what is the command to insert data into dataset?
what is wrong with the following code:
DataSetReasons.Data_Tracker_RcodeDataTable GRX =
new DataSetReasons.Data_Tracker_RcodeDataTable();
DataSetReasons.Data_Tracker_RcodeRow rowx =
DataSetReasons.Data_Tracker_RcodeRow();
rowx.dtrc_id = 5;
rowx.eval_id = 28;
rowx.dtcr_StaffNum = "505651";
rowx.dtrc_RC1 = "C";
rowx.dtrc_RC2 = "A";
rowx.dtrc_RM1 = 2;
rowx.dtrc_RM2 = 4;
GRX.Rows.Add(rowx);
you must add your datatable GRX to your dataset DataSetReasons.
DataSetReasons.Data_Tracker_RcodeDataTable GRX =
new DataSetReasons.Data_Tracker_RcodeDataTable();
DataSetReasons.Data_Tracker_RcodeRow rowx =
DataSetReasons.Data_Tracker_RcodeRow();
rowx.dtrc_id = 5;
rowx.eval_id = 28;
rowx.dtcr_StaffNum = "505651";
rowx.dtrc_RC1 = "C";
rowx.dtrc_RC2 = "A";
rowx.dtrc_RM1 = 2;
rowx.dtrc_RM2 = 4;
GRX.Rows.Add(rowx);
DataSetReasons.Tables.Add(GRX);//<--
Replace your code with the below line:
DataSetReasons.Data_Tracker_RcodeRow rowx = GRX.NewRow();
Regarding adding the datatable to a dataset, you have to create a dataset object and add the datatable to the dataset.
solved, thanks to everyone... here is the code:
DataSetReasons.Data_Tracker_RcodeDataTable GRX =
new DataSetReasons.Data_Tracker_RcodeDataTable();
GRX.Rows.Add(13, 28, "C", 5, "A", 2, TextBox2.Text);