c# rdlc Dataset properties data source error - c#

Please help,
I have a C# desktop application with .rdlc report and I use visual studio 2017
the report takes data from an object
for example:
public int ID {get; set;}
public string Name {get; set;}
the report is working very well BUT I needed to add a new field,
I added the field to the object and now I need to modify the report dataset
I removed the old dataset like I always do,
and then on report data window -right click on Datasets to choose New Dataset
now the dataset properties window opened and also popped up the data source configuration wizard,
this was not happening
anyway I chose (Object) as a data source type and --Next
in the next form I selected the object that I want and clicked --finish
error message popped up saying (Object reference not set to an instance of an object.)
The data source option is empty and choosing new and doing the same steps above did not solve it
I retried many times but it is the same
All references are correct
The application won't build because the dataset name is missing because I already deleted the dataset and not able to add any data new datasets
this never happened with me before
I am trying to delete the data source to redefine it again but I see no option for that
please tell me what should I do for that

Related

Unique identifier for Interop.ListObject from VSTO - C#

I need a way to insert (or use an already implemented property that could serve as) a unique identifier into a Microsoft.Office.Interop.Excel.ListObject instance.
The problem is that when I'm creating a new ListObject as:
var excelTable = worksheet.ListObjects.Add(ExcelInterop.XlListObjectSourceType.xlSrcExternal, DUMMY_CONNECTIONSTRING, false, true, cellRange);
I cannot rely on the Name property of excelTable to browse for it in the collection since the user could change the value of that property anytime afterwards.
After browsing trough the object properties I found nothing I could use out of the box (like a Tag property for example, which exists in a Microsoft.Office.Tools.Excel.ListObjecttype of object I cannot use at this point due to dependencies) ...and other weird stuff like a DisplayName that appears not only unable to be set directly but also to reflect the exact same value that the Name property has at all times (Why would you want to have 2 properties that reflect the same value at any time?).
I've thought on either creating my own implementation of this class or probably use the Comment property to store a GUID (which I don't know why kinda feels wrong):
excelTable.Comment = Guid.NewGuid().ToString();
Can you suggest of another way to accomplish this task?
Thanks a lot!
It is quite frustrating that there is no "Tag" (or similar) property that you could set on Excel objects. I'm facing the same issues as you. Here are two options that you can use:
alternative text property (for the table it is only visible by right clicking the table, selecting table and alternative text). This is probably a bit cleaner than Comment since the UI for comment is always visible.
you could also generate a wrapper object that contains a direct reference to the ListObject. So one wrapper object for each created ListObject. This works fine until you save / open the workbook again. If you need to be able to identify the table again after reopening the workbook you would still need to write some id to Comment or Alternative text. You could probably do a clean implementation by using events like BeforeSave and AfterSave (add alternative text before save so it saves to disk, then remove it again after save so that the user doesn't see it. When the workbook opens you load up your wrapper objects and remove the alternative text).

Object Teletransport

I have a object, better, a class. It is like a win form, with the parts:
class.cs, class.Designer.cs and the last class.Resx
It is an XtraReport, so what I'm doing is to get this object and serialize it into a xml file that holds enough information about its controls. The xml generated is used on another project, that uses just the xml. The problem is that it is not enough, despite the xml having all information, it still needs the origin object to resolve the controls properly. Basically:
Saving the Xml - First Solution(C# solution):
var originalReport = new MyCompleteReportDrawInDesignerMode();
original.SaveLayoutToXml(#"c:\FileToBeSerializedAndUsedInAnotherProject");
Consuming the Xml - Another solution(C# Solution)
var genericClass = new GenericClass();
genericClass.LoadLayoutFromXml(#"C:\FileGeneratedByDeserializedXML");
Both classes are child from XtraReports:
public class MyCompleteReportDrawInDesignerMode : XtraReport
public class GenericClass : XtraReport
this doest not work, since the Another Solution does not have a clue about MyCompleteReportDrawInDesignerMode. So i thought, why not teletransport the whole object and make it happen
//Build the object
var generator = GetObjectFromText(text);
//Resolve the dependecy check
var objectGenerated = generator.ResolveAssembly();
But I have no clue how to do it or if it is viable. Any thoughts ?
Update:
I wanna store the class implementation in the database and rebuild it from another application, since the xml transformation is causing information loss.
Let me introduce a little more deeper context. We are building a reporting server application. The process is basically:
1 - Desginer the XtraReport in designer mode, set the fields databindings, set the xrsubreports reportsource if any
2 - Make a xml file from it and save in local C:\ hard driver.
3 - In another application, the user uploads this file and serialize it into varbinary.
4 - The client side receives this serialized xml and restore it, then it trys to load into a generic XtraReport class.
So I would have to create and bound this assemblys at runtime, since we cannot relase a new version of our product every new report we built.
You need to make the MyCompleteReportDrawInDesignerMode class known by both solutions.
Make a separate class library assembly (separate project) that defines MyCompleteReportDrawInDesignerMode. This assembly (DLL) can then be referenced by both applications; the one that writes the report to an XML file and the one that reads this file and recreates the report.
the solution found was to create a class library visual studio solution, then we design the report, the subreports, and compile the all thing, and serialize the dll into a varbinary column in sql server. The dll is small, about 100 kbytes, so no problem.
After serialized into the database, the other application can consume the dll. In the same table, we put the namespace and class name from the main report, so you can create a instance at runtime, fill the datasource and print. I found that the xml serialization only works on the most recent devexpress versions, like: 13.1.10.
Here is the code:
Assembly local =
Assembly.LoadFile(#"C:\TempReports\5a788bc0-3e70-4f8b-8fa9-f180d23c4f03.dll");
Type t = _local.GetType("Relatórios_Teste.Reports.FluxoCaixa");
object test = Activator.CreateInstance(t);
var report = (XtraReport) test;
var controls = report.AllControls<XRSubreport>();
foreach (var control in controls)
{
if (control.Name.Equals("sub_detail"))
{
control.ReportSource.DataSource = GetSource();
control.ReportSource.DataMember = #"sp_test";
}
}
report.ShowPreview();

Reference a generated dataset

How would I reference and pull data out of a generated dataset?
I have 2 projects in the same solution.
(1) MyUIProject
(2) MyDataSetProject
->MyGeneratedDataSet.xsd
-->-->MyNamesTable (in the dataset)
All I want to do is reference the MyNamesTable and loop through the names in the table and put them in a list box. I'm having trouble getting the records out of the generated dataset.
I'm trying to do something like:
foreach (var name in MyDataSetProject.GeneratedDataSet.MyNamesTable)
{
MyDropDownList.Items.Add(new ListItem(name));
}
Thanks for any thoughts.
First thing to do is make sure your references are correct between your projects. Right click on your MyUIProject and click Add Reference. Go to the Projects tab and add your MyDataSetProject entry. If it gives you an error about it already have been added, then it's already added.
Second, you need to access your dll project classes from your website. Let's say in your website you have a page called Default.aspx, and in your dll project you have a class called DataSetAccessor, which looks like the following:
public class DataSetAcessor
{
public DataSet GetDataSet(<arguments>)
{
//populate the dataset and return it
}
}
You can then use this class in your Default page:
//at top
using MyDataSetProject; //this may vary
//down in some method
DataSetAccessor dsa = new DataSetAccessor();
DataSet data = dsa.GetDataSet();
foreach(DataRow row in data.Tables[0].Rows)
{
//using the values in row to populate your drop down list
}
Hopefully this help.

Importing a Dataset into RDLC file Wizard stopped working

Weeks ago I created a few (RDLC) reports. To create a Dataset I defined a dummy class and I imported with the procedure, it worked well.
public class DataSetCartaIntestata
{
public string Desc
public string Immage;
public string Name;
}
I did that to get the result of a query with Anonymous type:
public IEnumerable list;
list= b.Results.Where(x=>x.Name="Jack").Select(x=>new{x.Name,x.Image,x.Desc}).ToList();
Now it seems that if I'm going to do that again the procedure won't let me add a Dataset.
When I select new Dataset it creates the Datasource but not the Dataset.
Is there anything I got wrong?
i Found the answare is here the import pocedure import only properties not simple fields of a class even if they are public. so i had to define them.
anyway if I define by hand the Dataset in the RDLC i can access directly fields.
It's easier to make Mistake changing xml plus VS2012 is a bit touchy on the RDLC and crash a lot

LightSwitch - "Reference properties cannot be set to deleted or discarded entities."

I am experiencing this exception when trying to define a data member contained within another piece of data.
Example:
Container newRecord = this.DataWorkspace.ApplicationData.Containers.AddNew();
newRecord.SubContainer = this.DataWorkspace.ApplicationData.SubContainers.AddNew();
The exception, "Reference properties cannot be set to deleted or discarded entities.", is encountered with the second line.
I don't understand what entity it's talking about with regard to it being discarded or deleted, so any help with this issue would be most appreciated.
The code lines are in an interface function defined in LightSwitch, which is called from a Silverlight project, passing data from that project to the LightSwitch project.
I eventually managed to do this after working out that I needed to be on the 'Logic' thread, which I was not. I spent a little while messing around trying to find a this.DataContext but could not (my Silverlight project had this but not the LightSwitch project).
Eventually though I found out what I needed to do:
this.Details.Dispatcher.BeginInvoke(() =>
{
Container newRecord = this.DataWorkspace.ApplicationData.Containers.AddNew();
newRecord.SubContainer = this.DataWorkspace.ApplicationData.SubContainers.AddNew();
newRecord.exampleIntProperty=2;
newRecord.SubContainer.innerString="Example";
});
I can then assign data to the properties of newRecord and the properties of the objects it contains (such as the example SubContainer's properties), although obviously the new record is not saved until LightSwitch is instructed to save its data.
Your code needs to be changed slightly:
Container newRecord = this.DataWorkspace.ApplicationData.Containers.AddNew();
SubContainer newSub = newRecord.SubContainers.AddNew();
If the navigation property isn't called SubContainers, just replace that with the correct name.

Categories