I have a datagrid that displays data from an access database. When I run an update query, it works, but the datagrid does not update. After the update query runs I reset the ItemsSource.
Is there any solutions or ideas to fix this problem?
After the query runs, I call a function to fill the data grid:
fillDataGrid(string query)
{
DataTable table = new DataTable();
OleDbCommand cmd = new OleDbCommand(query, connection);
cmd.ExecuteNonQuery();
OleDbDataAdapter adapter = new OleDbDataAdapter(cmd);
adapter.Fill(table);
dgLogs.ItemsSource = table.DefaultView;
}
Related
I am trying to set an extended field value for INRegister after I create and insert a new INKitRegister object into the KitAssemblyEntry graph. I understand that the INKitRegister, on save, has a method which creates the INRegister that is stored in the database for the kit. After the save, I have code that I want to execute that would set the extension field I added to the INRegister data table. When this code executes, I get the following error:
Error #78: Another process has updated the 'INRegister' record. Your changes will be lost.
I'm not sure why since I execute this edit after the data table entry is completed.
Here is my code:
...//Code to create component children
INKitRegister kitHeader = new INKitRegister
{
//set header fields
};
//I also have this extended field on the INKitRegister DAC
INKitRegisterExt kitHeaderExt = PXCache<INKitRegister>.GetExtension<INKitRegisterExt>(kitHeader);
kitHeaderExt.UsrWOID = CurrentDocument.Current.Id;
INTranSplit kitParentAssembly = new INTranSplit
{
//Making INTranSplit entry for kit
};
...
//Do I need to get the graph's extension? set register view? do I need to get kitHeader's inserted refNbr and forward that to function to set woid?
KitAssemblyEntry graphKAE = PXGraph.CreateInstance<KitAssemblyEntry>();
graphKAE.Document.Insert(kitHeader);
graphKAE.Document.Current.KitRevisionID = "1";
graphKAE.Actions.PressSave();
foreach (INComponentTran ch in kitChildren)
{
ch.RefNbr = kitHeader.RefNbr;
graphKAE.Components.Insert(ch);
}
graphKAE.Actions.PressSave();
//Code in which I get the newly created INRegister and set the extended field.
string refNbr = graphKAE.Document.Current.RefNbr;
INRegister reg = PXSelect<INRegister, Where<INRegister.refNbr, Equal<Required<INRegister.refNbr>>, And<INRegister.docType, Equal<Required<INRegister.docType>>>>>
.Select(this, refNbr, "P");
INRegisterExt regExt = PXCache<INRegister>.GetExtension<INRegisterExt>(reg);
regExt.UsrWOID = CurrentDocument.Current.Id;
INRegisters.Update(reg);
this.Actions.PressSave();
PXRedirectHelper.TryRedirect(graphKAE, PXRedirectHelper.WindowMode.Popup);
Any suggestions? I tried placing the code in a KitAssemblyEntry_Extension class under INKitRegister_RowPersisting and INKitRegister_RowUpdating. I've also looked into possibly executing the update when the popup window closes, but I do not know how to do that. Any help is welcome to point me in the correct direction.
That indicates the record you have is not the latest as it exists in the database. Try using PXSelectReadonly in place of PXSelect to get your INRegister (reg) object.
I assume it is the line "INRegisters.Update(reg);" then save that is failing?
I would also try to use the kit graph to update the INRegister and select the inregister. Try changing this one section...
//Code in which I get the newly created INRegister and set the extended field.
string refNbr = graphKAE.Document.Current.RefNbr;
INRegister reg = PXSelectReadOnly<INRegister,
Where<INRegister.refNbr, Equal<Required<INRegister.refNbr>>,
And<INRegister.docType, Equal<Required<INRegister.docType>>>>>
.Select(graphKAE, refNbr, "P");
INRegisterExt regExt = PXCache<INRegister>.GetExtension<INRegisterExt>(reg);
regExt.UsrWOID = CurrentDocument.Current.Id;
graphKAE.Caches[typeof(INRegister)].PersistUpdated(graphKAE.Caches[typeof(INRegister)].Update(reg));
I was wondering if anybody here attempted creating an Automation Service to Export a DataTable to Xlsx in Spotfire Automation Services? I have been trying to create one but I am having issues. If anybody has been able to do this can you please share your project?
THis is the code I have thus far but having issues with Accessing the DataSource and DataTable.
protected override TaskExecutionStatus ExecuteCore(TaskExecutionContext context)
{
DataRowReader dataRowReader;
///Create a DataWriter
DataWriter writer = context.Application.CreateDataWriter(DataWriterTypeIdentifiers.ExcelXlsDataWriter);
///<summary>
///Call the DataWriter Core from here or call a class that will do the relevant work
///<toDO>Need to find a way to access the current DataTable of the Open Analysis</toDo>
///</summary>
Document doc = context.Application.Document;
if(doc == null)
return new TaskExecutionStatus(false, "NoAnalysisLoaded");
DataManager data = doc.Context.GetService<DataManager>();
DataTable table = data.Tables.Add(doc.ActiveDataTableReference, dataSource);
string fileName = context.ExpandTags(this.filePath);
FileStream fs = File.OpenWrite(fileName);
//See how to properly impliment the writers
writer.Write(fs, table, new IndexSet(table.RowCount, true), table.Columns.Names);
fs.Close();
data.Tables.Remove(table);
return new TaskExecutionStatus(true);
}
To get the active data table reference you should use
DataTable mytable = Application.Document.ActiveDataTableReference;
and then you can use mytable further in the code.
I'm associating record to some other entity using AssociateRequest.My question is how to Associate multiple records to subgrid.could you plz anyone clarify me.
Entity en=(Entity)context.InputParameters["Target"];
AssociateRequest assreq = new AssociateRequest();
assreq.Target = new EntityReference(en.LogicalName,en.Id);
assreq.RelatedEntities = new EntityReferenceCollection();
assreq.RelatedEntities.Add(new EntityReference("contact", new Guid("72C8B80B-FEF1-E311-9345-D89D67642EB0")));
assreq.Relationship = new Relationship("contact_customer_accounts");
AssociateResponse assresponse = (AssociateResponse)service.Execute(assreq);
The AssociateRequest can only be used to create a relationship between two records. If you need to associate a record multiple times, you will have to repeat the procedure for every single relationship.
You can pack the AssociateRequest's into an ExecuteMultipleRequest and save some roundtrips to the server. Please, keep in mind: the requests that are in the ExecuteMultipleRequest do not participate in the same database transaction.
OrganizationRequestCollection associateRequestCollection = new OrganizationRequestCollection();
Entity en = (Entity)context.InputParameters["Target"];
you will have to create AssociateRequest for every single
relationship and add them int associateRequestCollection object like below
AssociateRequest assreq = new AssociateRequest();
assreq.Target = new EntityReference(en.LogicalName, en.Id);
assreq.RelatedEntities = new EntityReferenceCollection();
assreq.RelatedEntities.Add(new EntityReference("contact", new Guid("72C8B80B-FEF1-E311-9345-D89D67642EB0")));
assreq.Relationship = new Relationship("contact_customer_accounts");
associateRequestCollection.Add(assreq);
//Process the Create Multiple emails against Contact Ids;
ExecuteMultipleResponse emResponses = ExecuteCRMMultipleRequest(associateRequestCollection);
private ExecuteMultipleResponse ExecuteCrmMultipleRequest(OrganizationRequestCollection associateRequestCollection)
{
ExecuteMultipleRequest emRequest = new ExecuteMultipleRequest
{
Requests = associateRequestCollection,
Settings = new ExecuteMultipleSettings
{
ContinueOnError = true,
ReturnResponses = true
}
};
return (ExecuteMultipleResponse)service.Execute(emRequest);
}
I am trying to find a way to use the result from my linq query as a datasource for a TreeView and GridView in C#, without having to save the file first in the server. Have tried various options, but all require that the document is saved as a file first. Can someone please help me out? The code is given below:
XDocument products = new XDocument(
new XDeclaration("1.0", "utf-8", ""),
new XElement("products",
new XElement("product", new XAttribute("id", "p1"),
new XElement("name", "Alpha"),
new XElement("Address", "200 WATERLOO DRIVE"),
new XElement("price",
new XElement("currency", "Rs.")),
new XElement("stock", "19"),
new XElement("country", "USA",
new XElement("state", "California"))),
new XElement("product", new XAttribute("id", "p2"),
new XElement("name", "Beta"),
new XElement("Address", "500 MOUNTBATTEN AVENUE"),
new XElement("price",
new XElement("currency", "Rs.")),
new XElement("stock", "25"),
new XElement("country", "USA",
new XElement("state", "Florida")))));
//create a linq query
var newxml = from f1 in products.Elements("product")
where (string)f1.Element("country").Element("state") != "Florida"
select f1;
//Create an xml document in memory using the linq query
XDocument xdoc = new XDocument(
new XDeclaration("1.0", "utf-8", ""),
new XElement("products"));
xdoc.Element("products").Add(newxml);
//create a datasource for TreeView or GridView using the xml document in memory.
XmlDataSource xmlds = new XmlDataSource();
xmlds.DataFile=xdoc;
TreeView1.DataSource = xmlds;
TreeView1.DataBind();
GridView1.DataSource = xmlds;
GridView1.DataBind();
The part of the code for creating the datasource from xdoc is not working. It can be made to work by saving the file and then calling the file for the datasource, but I want do do this from the memory.
you can use the linq query result directly as datasource.
gridview1.datasource = newxml;
gridview1.databind();
drawback i have encountered is that for e.g sorting to work you will need to implement own sort method.
//Create a User Control with a TextBlock
TextBlock textBlock = new TextBlock();
textBlock.Text = "Helo";
UserControl userCOntrol = new UserControl();
userCOntrol.Content = textBlock;
//Add the UserControl to a Table
table.RowGroups[0].Rows[0].Cells[0].Blocks.Add(new Paragraph(new InlineUIContainer(userCOntrol as UIElement)));
//Add the table to a FlowDocument
FlowDocument flowDocument = new FlowDocument();
flowDocument.Blocks.Add(table);
//Fetch the Visual representation of the page.
DocumentPage page = ((IDocumentPaginatorSource)flowDocument).DocumentPaginator.GetPage(0);
//Extract the Visual from the page and add to a Fixed Page
FixedPage fixedPage = new FixedPage();
ContainerVisual container = new ContainerVisual();
container.Children.Add(page.Visual);
DrawingCanvas canvas= new DrawingCanvas();
canvas.AddVisual(container);
fixedPage.Children.Add(canvas);
//now write the FixedPage to an XPS file
using (XpsDocument xpsDoc = new XpsDocument("c:\\x.xps", FileAccess.ReadWrite))
{
XpsDocumentWriter xpsDw = XpsDocument.CreateXpsDocumentWriter(xpsDoc);
xpsDw.Write(kj);
}
The above piece of code releases nothing. Once the flowdocument is paginated and Visual representation of the page fetched, the contents of the flowdocument are refernced by the Visual. so neither Visual gets disposed nor the contents of flowdocument.
The above piece of code when executed continuously raised out of memory.
Does anyone know how to release the memory held by all these resources?
Thanks in advance.