I'm using Datatable as data source of crystal report , but loading reports is very slow because of amount of data is big , let empdepttbl is the datatable , i'm using this loop to set data to the rows of datatable
for (i = 0; i < dt.Rows.Count; i++)
{
empdepttbl.Rows.Add(new Object[]{dt.Rows[i][7].ToString(),month[mon],dt.Rows[i][2].ToString(),dt.Rows[i][3].ToString(),dt.Rows[i][4].ToString(),string.Format("{0:#,###0}",t)});
}
dt is the Datatable which contains data that selected from database ..
so, how can I setting data directly without using loop ?
Try This and dont forget mark as answer if work
foreach(var item in dt)
{
empdepttbl.Rows.Add(new Object[]{item [7].ToString(),month[mon],item [2].ToString(),item [3].ToString(),item [4].ToString(),string.Format("{0:#,###0}",t)});
}
And you Can Use the dt direct in crystal report data source
Related
My Interactive Grid has column caled "EMPL_STAT1".
I use the code below to get the return value of the select list from selected record.
Works fine but I was wondering how to change that code to get the return value of the select list from each record (not selected only) in "EMPL_STAT1" column?
Could you give me any advice?
var reg = apex.region('ig_emp').widget();
var grid = reg.interactiveGrid("getViews","grid");
var model = reg.interactiveGrid("getViews","grid").model;
var selectedRecords = grid.getSelectedRecords();
for (i = 0; i < selectedRecords.length; i++)
{
record = model.getRecord(selectedRecords[i][0]);
itemcodeField = model.getFieldKey("EMPL_STAT1");
alert(record[itemcodeField].v);
}
The Javascript you shared, gets the selected row records only.
Let's say my IG's static ID is igTest
var model = apex.region("igTest").widget().interactiveGrid("getViews", "grid").model;
model.forEach(function(igrow) {
console.log(igrow[model.getFieldKey("FIRST_NAME")]);
});
This will loop through all the records in the IG.
I'm trying to create a datatable in microsoft ax x++.
I need to return some information back to a webservice. Problem is i'm having trouble getting this code to work. it runs to the point where i try to add a column because apparently that function doesn't work....
Does anyone have the code in full to create a datatable in x++. this code works up until the column code.. because basically what i'm doing is query some information and returning it back to a webservice.. unless theres another way to return multiple information back to a webservice that uses c#
System.Data.DataTable dt = new System.Data.DataTable("MyTable");
System.Data.DataColumnCollection columns = dt.get_Columns();
System.Data.DataColumn ProductName;
System.Data.DataColumn QtyOrdered;
System.Data.DataColumn ProductID;
System.Data.DataRow row;
ProductID = new System.Data.DataColumn("ProductID", System.Type::GetType("System.Int32"));
ProductName = new System.Data.DataColumn("ProductName", System.Type::GetType("System.String"));
QtyOrdered = new System.Data.DataColumn("QtyOrdered", System.Type::GetType("System.String"));
// dt.Columns.Add(ProductID);
// dt.Columns.Add(ProductName);
// dt.Columns.Add(QtyOrdered);
row=dt.NewRow();
Did you try replacing lines
// dt.Columns.Add(ProductID);
// dt.Columns.Add(ProductName);
// dt.Columns.Add(QtyOrdered);
with
columns.Add(ProductID);
columns.Add(ProductName);
columns.Add(QtyOrdered);
?
P.S. To populate the row:
System.Data.DataRowCollection rows = dt.get_Rows();
...
row = dt.NewRow();
row.set_Item("ProductID", 1);
row.set_Item("ProductName", "PN");
row.set_Item("QtyOrdered", "QO");
rows.Add(row);
I suggest you to read some MSDN articles such as .NET Interop from X++, How To Use X++ Syntax for CLR Arrays, etc. - it should help you understand how to use .NET assemblies from X++.
I am getting a datatable from service. I am using linq to calculate of sum new columns. I want all the coumns in datatable originally plus the new columns calculated in linq.
Problem is columns in datatable are not fixed. How would I dynamically add the columns in select clause of linq.
Below is code snippet:
DataTable dt = ds.Tables[0];
var orderCtr =
from o in dt.AsEnumerable()
where o.Field<string>(Constants.GENDER_NAME) != "Unknown"
group o by new
{
odr_id = o.Field<int>(Constants.ORDER_ID),
//NEED TO ADD COLUMNS DYNAMICALLY HERE. MEANS IF THEY ARE IN DATATABLE.
}
into g
select new
{
//NEED TO ADD COLUMNS DYNAMICALLY HERE. MEANS IF THEY ARE IN DATATABLE.
odr_id = g.Key.odr_id,
ac_gr_imp = g.Sum(r => r.Field<long>(Constants.GENDER_IMPRESSION)),
ac_gr_clk = g.Sum(r => r.Field<long>(Constants.GENDER_CLICK)),
Ctr = (double)g.Sum(r => r.Field<long>(Constants.GENDER_IMPRESSION)) / g.Sum(r => r.Field<long>(Constants.GENDER_CLICK)),
};
You might be interested in the Dynamic LINQ library. Dynamic LINQ allows you to specify queries or parts of queries by building strings.
Scott Guthrie described it back in 2008 (http://weblogs.asp.net/scottgu/archive/2008/01/07/dynamic-linq-part-1-using-the-linq-dynamic-query-library.aspx) and there is also a NuGet package of it in case you use .NET 4 (http://www.nuget.org/packages/System.Linq.Dynamic).
I am updating values in an Excel workbook using values from a MySQL database. There are just eleven rows in the WorkbookMap list, and six DataTables in the RptValueSet DataSet. I've proven that the problem is in this loop, not in the communication with the database. Getting the results is fast, but writing them to the workbook is slow. The code below works fine when the DataTables in the DataSet are small - such as a 3-column, 7-row results set, and I receive the updated Excel workbook almost instantly. However, the loop slows down noticeably when the results set increases; a 3-column, 50-row DataTable results in a 7 - 10 second delay in returning the updated Excel workbook. I'm not sure I really need to put the DataTables into a collection, but that's the only way I could figure out how to iterate over them. Any tips on optimizing this loop would be much appreciated!
// Create a list to contain the destination for the data in the workbook
List<WorkbookMap> wbMap = new List<WorkbookMap>();
// Create a new data set to contain results from database
DataSet RptValuesSet = new DataSet();
// RptValuesSet populated from database here....
// Create a collection so we can loop thru the dataset
DataTableCollection RptValuesColl = RptValuesSet.Tables;
for (int i = 0; i < RptValuesColl.Count; i++)
{
DataTable tbl = RptValuesColl[i];
// Find the correct entry in the workbook map
for (int j = 0; j < wbMap.Count; j++)
{
if (wbMap[j].SPCall == tbl.TableName)
{
// Write the results to the correct location in the workbook
MovingColumnRef = wbMap[j].StartColumn;
for (int c = 1; c < tbl.Columns.Count; c++)
{
row = wbMap[j].StartRow; // start at the top row for each new column
for (int r = 0; r < tbl.Rows.Count; r++)
{
// Write the database value to the workbook given the sheetName and cell address
UpdateValue(wbMap[j].SheetName, MovingColumnRef + row, tbl.Rows[r][c].ToString(), 0, wbMap[j].String);
row++;
}
MovingColumnRef = IncrementColRef(MovingColumnRef);
}
}
}
}
Without delving deeply into your code. I noticed you said that you believe the slowness is coming from writing to the sheet. Try putting the data into an Array first before updating the workbook. E.g. you would write to the sheet like this. anchorRangeName is the name of a range which would be only one cell in the workbook.
private void WriteResultToRange(Excel.Workbook wb, string anchorRangeName, object[,] resultArray)
{
Excel.Range resultRange = GetRange(anchorRangeName, wb).get_Resize(resultArray.GetLength(0), resultArray.GetLength(1));
resultRange.Value2 = resultArray;
}
You'll still need to get the data from the database into an array.
I'm using the LinqToExcel library. Working great so far, except that I need to start the query at a specific row. This is because the excel spreadsheet from the client uses some images and "header" information at the top of the excel file before the data actually starts.
The data itself will be simple to read and is fairly generic, I just need to know how to tell the ExcelQueryFactory to start at a specific row.
I am aware of the WorksheetRange<Company>("B3", "G10") option, but I don't want to specify an ending row, just where to start reading the file.
Using the latest v. of LinqToExcel with C#
I just tried this code and it seemed to work just fine:
var book = new LinqToExcel.ExcelQueryFactory(#"E:\Temporary\Book1.xlsx");
var query =
from row in book.WorksheetRange("A4", "B16384")
select new
{
Name = row["Name"].Cast<string>(),
Age = row["Age"].Cast<int>(),
};
I only got back the rows with data.
I suppose that you already solved this, but maybe for others - looks like you can use
var excel = new ExcelQueryFactory(path);
var allRows = excel.WorksheetNoHeader();
//start from 3rd row (zero-based indexing), length = allRows.Count() or computed range of rows you want
for (int i = 2; i < length; i++)
{
RowNoHeader row = allRows.ElementAtOrDefault(i);
//process the row - access columns as you want - also zero-based indexing
}
Not as simple as specifying some Range("B3", ...), but also the way.
Hope this helps at least somebody ;)
I had tried this, works fine for my scenario.
//get the sheets info
var faceWrksheet = excel.Worksheet(facemechSheetName);
// get the total rows count.
int _faceMechRows = faceWrksheet.Count();
// append with End Range.
var faceMechResult = excel.WorksheetRange<ExcelFaceMech>("A5", "AS" + _faceMechRows.ToString(), SheetName).
Where(i => i.WorkOrder != null).Select(x => x).ToList();
Have you tried WorksheetRange<Company>("B3", "G")
Unforunatly, at this moment and iteration in the LinqToExcel framework, there does not appear to be any way to do this.
To get around this we are requiring the client to have the data to be uploaded in it's own "sheet" within the excel document. The header row at the first row and the data under it. If they want any "meta data" they will need to include this in another sheet. Below is an example from the LinqToExcel documentation on how to query off a specific sheet.
var excel = new ExcelQueryFactory("excelFileName");
var oldCompanies = from c in repo.Worksheet<Company>("US Companies") //worksheet name = 'US Companies'
where c.LaunchDate < new DateTime(1900, 0, 0)
select c;