C# rdlc for a single object, no table - c#

I'm trying to make an rdlc report in Visual Studio 2015 for a single instance of an object. It seems as though I always have to pass in an enumerable list as the datasource, and it always has a table.
Is it possible to just pass in a single object and not have a table? I want to have a background image and use text boxes to display the data that I want to display.
Thank you for any responses!

There are a couple of ways to accomplish this.
If it's just a single item, why not just use a parameter? Just pass your single value via a parameter.
If you want to go the data source route, yes, you have pass in an enumerable, but that is as easy as this:
var data = new string[] { "my value"}
and using the First function:
=First(Fields!ProductNumber.Value, "Category")
Either way, you can still use textboxes.

Related

Creating repeatable columns for a Sharepoint 2010 List

I'm trying to create a list that allows me to store multiple instances of a single column.
Say I have a column names "steps" which is a single line of text, and I want the user to be able to add as many as possible.
Can I do this currently in Sharepoint Lists?
Bonus points for allowing me to do it in a LoopUp column, for more complex types.
You will need to create a "Custom Field Type" to do this. Then you can delimit your different lines somehow (the internal columns link Multi-lookup, multi-choice etc use ;# as a delimiter but you can use whatever)
http://msdn.microsoft.com/en-us/library/ms446361.aspx
http://msdn.microsoft.com/en-us/library/bb684919(v=office.12).aspx
http://sharepointmagazine.net/articles/customizing-the-user-experience-of-sharepoint-custom-fields-deep-dive-part-5-of-6

C# Referencing a dataSets property without using it's name

Anyone know how to reference a dataSet for example if I called it dataSet5 and don't want to use it's name.
For example if I would normally use this call to display a particular tables cell value
MessageBox.Show(dataSet5.Tables[0].Rows[0][0].ToString());
How can I do the same as above using indexing so I can throw it in an incrementing loop similar to below which doesn't work. I was hoping maybe it's either part of an array of form elements or components that way I can access it something like below.
MessageBox.Show(dataSets[24].Tables[0].Rows[0][0].ToString());
Using SharpDevelop
If you want to call datasets by index you have to have an array of dataset.
DataSet[] alldatasets = new DataSet[5];
Even better if you put the datasets in a List. IE.
List<DataSet> listDatasets = new List<DataSet>();
listDatasets.Add(new DataSet());
listDatasets[0].Tables[0].Rows[0][0].ToString();
You need to put the DataSets into your own array:
private DataSet[] dataSets;
...
dataSets = new DataSet[] { ... };

How to get an Item from an auto-populated DataGrid?

I have a DataGrid that is automatically fed certain values from an LINQ-To-SQL-Source. The headers of the DataGrid are also auto-generated. I simply want one of the Cells of the currently selected item within the data-grid.
var a = TestGrid.SelectedCells[0].Item;
If I debug this I get a List containing all the values I need:
TestGrid.SelectedCells[0].Item{ Datum = {11.05.2011 00:00:00}, ID = 3, name = "db",Status = "Ready" }<Anonymous Type>
I have absolutely no idea how to select the second item(ID) from that anonymous type, and google isn't helping
The best option would be to create a type to hold your values and store that in your DataGrid. If you're only using it for display, the anonymous types are fine to use. The moment you need to use them for anything else, they are not so great.
If you really want to stick to anonymous types, the only option you have is to use reflection. If this is specifically a C# 4.0+ app, then using dynamic can make this somewhat easier.

How can I create a simple class that is similar to a datatable, but without the overhead?

I want to create a simple class that is similar to a datatable, but without the overhead.
So loading the object with a sqldatareader, and then return this custom datatable-like object that will give me access to the rows and columns like:
myObject[rowID]["columnname"]
How would you go about creating such an object?
I don't want any built in methods/behavior for this object except for accessing the rows and columns of the data.
Update:
I don't want a datable, I want something much leaner (plus I want to learn how to create such an object).
This type of structure can be easily created with a type signature of:
List<Dictionary<string, object>>
This will allow access as you specify and should be pretty easy to populate.
You can always create an object that inherits from List < Dictionary < string, object > > and implements a constructor that takes a SqlDataReader. This constructor should create a enw dictionary for each row, and insert a new entry into the dictionary for each column, using the column name as the key.
I think you're missing something about how .Net works. The extra overhead involved in a DataTable is not significant. Can you point to a specific performance problem in existing code that you believe is caused by a datatable? Perhaps we can help correct that in a more elegant way.
Perhaps the specific thing you're asking about is how to use the convenient ["whatever"] indexing syntax in your own table object.
If so, I suggest you refer to this MSDN page on indexers.
Dictionary<int,object[]> would be better than List<Dictionary<string, object>>. You don't really need a dictionary for each row, since column names are the same for all rows. And if you want to have it lightweight, you should use column indexes instead of names.
So if you have a column "Name" that is a 3rd column, to get its value "Name" from a row ID 10, the code would be:
object val = table[10][2];
Another option is SortedList<int,object[]>... depending on the way you access the data (forward only or random access).
You could also use MultiDictionary<int,object> from PowerCollections.
From the memory usage perspective, I think the best option would be to use a single dimension array with some slack capacity. So after each, say 100, rows, you would create a new array, copy the old contents to it and leave 100 empty rows at the end. But you would have to keep some sort of an index when you delete a row, so that it is marked as deleted without resizing the array.
Isn't this a DataSet/DataTable? Maybe I didn't get the question.
Also, what is the programming language?

Assign multiple values to a parameter in Crystal Reports

I have added a parameter to my report with the option "Allow Multiple Values" checked.
This is a status column (IE, Proposed, In Progress, Completed, Canceled), and I want the user to be able to select which (and how many) different OrderStatus to report on.
How I normally set parameters is:
report.SetParameterValue("#dtBegin", dtBegin.DateTime);
What I tried to do for the multiple values was something like this:
//pseudo loop
foreach(int intOrderStatus in intSelectedOrderStatuses)
{
report.Parameter_OrderStatus.CurrentValues.AddValue(intOrderStatus);
}
I have checked it does add the values to the OrderStatus parameter, but when the report runs, the CrystalReports dialog pops up and asks me to enter values for the OrderStatus parameter. So it seems as though the values aren't "commited" to the parameter. I have done a number of searches and can't figure out why it's not working.
Thanks,
Just set the parameter value with an array of ints.
report.SetParameterValue("#OrderStatus", new int[]{1,2,3});
in the select expert you would use the in operator.
{table.order_status_id} in {?#OrderStatus}
What you can do is, make a normal parameter field,i.e without multiple values, only discreet values true, all you need to pass is 1,2,3,4. "," is the delimiter for separation use what ever you think works for you, then in record selection formula simply put
{table.order_status_id} in split({#OrderStatus}, ",")
all you need to pass from you page is the string 1,2,3,4 and it should work
Have you set the parameter to Hidden in the Crystal Reports parameter options?
I haven't tried this, but I think that you should be able to add intOrderStatus to either a ParameterDiscreteValue or ParameterRangeValue and pass that into Parameter_OrderStatus.CurrentValues instead of intOrderStatus.
Well i have same issue. The work around is very simple. Don't add data source after parameters. e.g
report.SetParameterValue("#dtBegin", dtBegin.DateTime);
report.SetParameterValue("#dtBegin2", dtBegin.DateTime1);
//Note datasource is assigned after parameters
report.SetDatasource(dataset);
The crystal report will refresh parameters before applying data source to report.
The below is the not popup discrete dialog box
//Note Datasource is applied before parameters
report.SetDatasource(dataset);
report.SetParameterValue("#dtBegin", dtBegin.DateTime);
report.SetParameterValue("#dtBegin2", dtBegin.DateTime1);
Following is tested in Crystal Reports version 13.0.20:
1) In Parameter Fields section add new parameter as follow:
Name: ParamMultipleOrderStatus
Type: Number
Value Options:
Allow multiple values: true
2) Choose the Select Expert Record ... in Crystal Reports and code may like this (use = operator):
{Orders.OrderStatus} = {?ParamMultipleOrderStatus}
3) Use following code:
foreach (int intOrderStatus in intSelectedOrderStatuses)
{
report.ParameterFields["ParamMultipleOrderStatus"].CurrentValues.AddValue(intOrderStatus);
}

Categories