how to fill Dataset with custom built DataTable using c#? - c#

I have to make a report.rdlc where i have to pass a dataset to it
I have DataTable made using C# not SQLDATAADAPTER other wise it can be filled as
adpt.fill(ds);
but i have only custom built DataTable using c# having columns and rows
How to make it datasource of report or make it dataset

Actually Simple... A Dataset is nothing but a collection of "DataTable" instances. You should be able to do via..
var DS = new DataSet();
YourCustomPopulatedDataTable.TableName = "SomeTable";
DS.Tables.Add( YourCustomPopulatedDataTable );
What * have done was created a baseline "ReportManager" class, but after I get the dataset with data back, I Write the XML output but also the XSD something like
DS.WriteXmlSchema( "MyXYZReport.xsd"); // the report will get this in a moment
DS.WriteXml( "MyXYZReport.xml");
Then, modify your project and add the ".xsd" file created so you don't have to fat-finger the schema for the report. So, the first time through, I query the data, generate the XSD/XML and stop before the actual report. Then, modify the project and add the XSD to it.
Now, open your rdlc. On the left-side you should have a panel for "Report Data". If not, click anywhere within your report, but not a specific object. Just enough to give focus you are working with the .RDLC. Then, click on "View" from the menu and the last item should show "Report Data" option. Once that is displayed, it will show how / where data comes from, parameters, images, data sources, data sets, etc.
Click on DataSets, right-click to Add Dataset and pick the .XSD you added to your project. This will display a dialog prompting with a "Name" to refer as in the report, then a data source. The Data Source should list the name such as "MyXYZReport". Under that will be "Available Datasets" and have the name of the tables within your dataset. Notice the one line change I did above to "name" the table before writing the XSD. Whatever that name is ("SomeTable" ), should be listed in the Available Datasets. Select that. Then, from my purpose, I change the "Name" of the dataset (the first field in the dialog) to the same value "SomeTable". This way, I am not guessing at which name is which. They will all refer to this as "SomeTable".
Now, in the report when you start adding controls, the expression dialog will show your "known" datasets (table instances) and associated fields to go.

Related

Adjust table adapter on Win Form to allow an expression

I have a form with a Data Grid View for personnel assigned to a project. I currently have a singular drop down that allows you to add people to the project which pulls all names of people based on a main roster. I figured out how to do this by editing the columns properties and using DisplayMember however, it only allows for one column selection and not an expression.
We have only a couple of people with the same last name however, it's caused headaches in the past. I want the drop down to pull in last name, first name. I've read a few things like using an expression property but haven't be able to find that. It seems a bit different than other posts I've read mainly because Visual Studio created Binding Sources and Table Adapters and I can't seem to edit this individual control column. Everything I've read shows how to do this by programatically creating a table but not by editing an existing one. I have an SQL view set up that solves this but am unable to set the control to a view or another query. So what's the best way to edit the adapter without creating the column on the actual table?
Thanks for any help.
Don
Followed this but wasn't able to get it to work with the DataGridView and adpaters.
https://learn.microsoft.com/en-us/dotnet/api/system.data.datacolumn.expression?redirectedfrom=MSDN&view=netframework-4.7.2#System_Data_DataColumn_Expression
This hasn't really got anything to do with the grid or the table adapter, so that would explain why you can't find it. Expression is a property of a DataColumn, i.e. a column in a DataTable, so that's where you need to make the change. If you have a typed DataSet then you make changes to it in the DataSet designer.
Open your DataSet in the designer. Right-click the appropriate table and select Add -> Column. Enter the name of the column in the table, then open the Properties window and set the Expression property. I just tested with a Person table with GivenName and FamilyName columns, adding a FullName column and setting the Expression to GivenName + ' ' + FamilyName. Once you save that, you can see in the Data Sources window that your table now has the extra column. If you drag that table onto a form, it will create a DataGridView with a corresponding column. If you already have a DataGridView then you can add a new column yourself and set its DataPropertyName so it binds to your new expression column.

Specify a "where clause" when using a ReportViewer control and Report w/ Oracle

I am attempting to use the ReportViewer control with an Report (RDLC) file in local processing mode using an Oracle DB, and I cannot figure out how to specify a "where clause" in my query. I just want to return 1 row, as my report will be based on just 1 row from the query.
Here is what I have done so far:
I created a C# Windows Form Application (.NET 4.5) in Visual Studio 2013.
I added a DataSet named DataSet1.
I added a TableAdapter to the DataSet and created a connection to Oracle added a query. Here is the query "select * from Lei_Defect_Log". (It pulled
in the column names.)
I added a Report named Report1 to the project.
On the "Report Data" window, I set the Dataset to the dataset I added
above.
I dragged a few arbitrary columns from the Report Data window
Dataset1 to the Report1 so I could verify it is working.
I added a ReportViewer named reportViewer1 to Form1 of the project. I set the
Report of the reportViewer1 to Report1 created above.
Now, when I run the application, the report displays data from the query (must be the first row returned). But the table I am pulling from (Lei_Defect_Log) has thousands of rows, and I want to specify a where clause in my query to just return 1 specific row. (I want to do this in the code, and not prompt the user for it.)
I tried adding a where clause in the TableAdapter query as follows "select * from Lei_Defect_Log where RA_SN = :RA_SN_PARAM" which would be a correct query for Oracle, but I received the following error:
The wizard detected the following problems when configuring the TableAdapter: "Fill":
Details:
Generated SELECT statement.
Specified argument was out of the range of valid values.
It would allow me to click OK, but if I clicked OK my DataSet would not populate the column names. So no go.
I have been at this for many hours...and am stuck.
Everything I have seems to work, but I just need to be able to add a where clause to specify the row I need.
So how do I specify a where clause (in the code or designer, I don't want the user to be prompted for it) so my query returns just one row/record?
Found it!
In the DataSet I right clicked on the TableAdapter and clicked "Configure" on the menu that opened. I added the parameter to the query like I did above and clicked Finish, then clicked OK and ignored the error. Then I right clicked on the text that says "FILL, GETDATA" and clicked Properties. Now go to the main Properties window and it should be the properties for the "Fill Query". Look for the Parameters property and open the Collection and set the DbType from Object to String..and it works!!!
See this WEB PAGE for screenshots (I would have posted but need more SO cred to do so.)

Multiple row input in asp.net for editing database table

From time to time, I need to create an input control which allows multiple rows of input, the type of input and number of columns could be different in each case but typically it would be represent a database table being edited, so it should also be possible to store an id value within each row. It should also be possible for the user to add new rows to the input if they have more data to input.
I have tried a couple of approaches to this but they are all very long winded for what seems like such an obvious and common scenario. I'm thinking that there must be a simple way to do this that I have missed.
The way that I usually solve this is by using a list view, enter all of the input controls required within the item template and use a html table for formatting, with each item being a row of the table. If there is existing data to be edited, I would load the data from the database, add a blank object to the results and bind it to the list view. If there is no existing data, I would create a collection with a blank record in it and bind it to the list view. I add a button for adding a new row. When clicked, this button retrieves all of the existing data from the list view by iterating all of the listview items and populating the data into a collection, which I would then add a blank object to and rebind the listview with the results. When saving, I would retrieve the results by iterating the listview items again and using a hidden field within each row to store the record id. This would determine whether a new record was added or an existing record was edited.
This approach works for me but I'm sure there must be simpler ways to achieve this. Looking forward to seeing how other people solve this.
For web forms, use a GridView. You can set its properties to allow editing, deleting, new rows, sorting, and paging.
Check out the MSDN example here that shows how to use it. If you bind a datasource to it, it will figure out the columns and adjust dynamically then, or you can predefine the columns you want for more customability.
You are talking about bulk insert/update. You could use XML insertion/updation for this purpose. Get all the data to a DataSet ds variable. Then use ds.GetXml() method to convert the dataset to XML string. Pass this to an XML parameter into SQL server which has the datatype 'XML'
INSERT INTO YOURTABLE
SELECT
V.VOI.value('(.)[1]', 'int')
FROM
#Input.nodes('/DATASETNAME/DATATABLENAME/') V(VOI)
Use this link to learn more
You need dynamic table with Add, View,Edit and delete operations on each data.
I would suggest using DataTable Jquery component. there are tons of examples on Data operations, and you can plug this with any Server technology including ASP.net
http://editor.datatables.net/

Combine two datasets in one Crystal Report

I want to create a type of Summary report for an account. The report should have a chart of account data from one data source AND a grid of different account data from another data source.
I want to use all of the data from table one where account_ID = X AND I want to use all of the data from table two where account_ID = x.
Crystal Reports will let me add two different datasources, but It wants to link them to create a sub report in a Master / Details kind of way. I need to report on ALL of the data in table one, and all of the data in table two.
I'm a bit confused on how to do that.
Note: When I'm doing this for one report only, I just create a datatable from a view filtered by the account_ID and then set that as the datasource for the report. That way the heavy lifting is done before Crystal Reports gets the data. Again, not sure how to do that for two different datasources.
If the datasets are different enough that a JOIN doesn't make sense, you'll want to use a sub-report. First, create the report as if you were only using one of the data sets. Then, insert a sub-report where you want the second grid to show up (go to Insert --> Subreport); usually putting it in a new section. Build the sub-report using only the second dataset -- it may help to think of it as a full report in itself, as if the main report didn't exist.
Right-click the sub-report "field" in the main report and select Change Subreport Links. Add the account_ID field and you'll automatically get a parameter, Pm-Table.account-ID, and basic select expert in the sub-report itself.
Double-click it, and you'll get a new tab for just the sub-report. In the long run, you'll want most of the sections suppressed, so the output is just the grid.
Once all that is done, running the main report will display both sets of results.

How to add the data source to the rdlc file in visual studio 2010?

I am new to windows desktop application development.
I want to generate a bill report that is the bill master details should be displayed once and the related items should be displayed in the tabular format.
I have created the data table in dataset. The data table is configured.
Now in the report design I am not able to see this table to drag the field to their proper position.
Please help how to do so.
Thanks in advance.
Adding datasets
First you have to add a Data Source in your Report. You can do this by using the Data Sources window in VS. Click the Add new data source and select what you want (I usually use object). In the Report Data window there is a folder 'Datasets'. If you right-click it you can add a dataset.
Data in a table
To visualize the dataset you can drag a Table from your Toolbox onto the report, select it, then right-click on the upper-left corner and select Tablix Properties. There you can bind a Dataset to the table. Choose which items you want to display in which column by clicking on the column and selecting a value.
Singular data (textbox)
You can set an expression on a textbox that retrieves a specific set of data from a dataset (you can also use this on table columns btw). You can do this by right-clicking the textbox en going to Expression. This will open up an Expression window that contains some sort of expression builder.
The expression I use to retrieve singular data is the following (not sure if this is the best approach but it's the only one I know):
First(Fields!MyField.Value, "MyDatasetName")
Basically I'm assuming there is only one row in my dataset (or that field is the same in all rows) so I'm just retrieving the first value.

Categories

Resources