XtraPivotGrid dynamic dataset creation - c#

I already have a dynamic XtraPivotGrid creation, but the table adapter and the dataset are 1(one) table specific. I want to be able to get data from a table specified by user, but I can't see a way of doing this without writing about 2.5k lines of code (writing the same code the IDE creates in design time, but for any table). Does anybody think in an easier way of doing this?

In similar situations I was creating the XtraGrid in design time, but then just changed the DataSource at runtime based on the user table selection. Then I was using the built in methods of XtraGrid to automatically create the columns. There is an article at DevExpress that might help.

Related

When and how to use DataSource instead of direct SqlConnection

I'm trying to learn SQL and how to use it in my C# projects, but I'm struggling to understand how to connect it. So far I've seen most people simply do
using (var connection = new SqlConnection(Properties.Settings.Default.TestConnectionString))
{
connection.Open();
/..
}
But in Visual Studio 2017, there is a tab for DataSource. Once I set my database connection there, I get a generated file DbNameTest, which I don't see to serve any purpose at all, there is no loaded data in it because I'm creating new instance of it every time I try to access it, I can save it, but I will still need to populate it the first time.
What's the point of using the DataSource tab and what's the purpose of the the DataSet?
This is a profound subject that has many answers and methods. I'll try to explain it simply.
The datasource tab consists of ready-made structures presented to developers. With the help of the components in this tab, you can do many operations with dragging and dropping the code.
However, many developers prefer to build a more extensible and manageable structure by writing code instead of drag and drop with ready components.
DataSet; It is a copy of the database in ADO.NET. A dataset can contain one or more DataTables. DataTables are database tables.

Building a model - based RDLC report

Objective
Build a PDF file which represents single C# class object with multiple fields and properties, that is created in runtime. It constains plain text, variables, tables, images.
What I have to use?
As a requirement, I have to render PDF report with Microsoft.Reporting.WebForms.LocalReport and it will probably contain SubReports.
What I did?
When working with reports until now, following simple pattern was enough:
ReportParameter param = new ReportParameter();
param.Name = "Param name";
but in that case I'd have to make over 80 parameters and I think it's just not a nice way, so I'm curious if there is better way to do that. Based on my researchers on SO and google, I can use System.Data.DataSet to achieve what I want, but:
It is only sightly better that hardcoding all the parameters
It is almost the same, but I produce additional files, IMO it's easier to use and understand ReportParameter way for future code users than getting burried in tons of extra files, that(maybe) could have been avoided
DataSets are for tabular data; I have one big model
Problem
Actually, I think the problem lies in DataSource of the RDLC report itself. The ways that VS provides are created for DB connection or any DB related object. That's why using DataSources and DataSets is indicated. I can provide any data that is either of type IEnumerable or IReportData (or from db connection), but mine are neither. I got my model already build and I'd want to use it if possible.
Most examples I found was for creating reports straight from database or custom data sets. Got no more ideas how to make it work. That's why I'm here.
When using an external component is an option for you: I've been using the .NET reporting component "combit List & Label". It has PDF export and an object dataprovider included that takes any .NET object or even object structure and provides the object`s properties as variables/parameters in an interactive report designer for tables, charts, etc.

DevExpress Winforms XtraGrid and SQLite bound database, best way to insert rows?

I have successfully bound a SQLite database table to a DevExpress XtraGrid control, and can see the few test rows I have, and can also edit the values, and commit the changes back to the database with an Update command upon closing.
My question is what would be the best way for me to insert rows to the table? I have implemented and successfully used some example code for inserting rows into a SQLite table, however I am uncertain if the DevExpress XtraGrid has some type of method to allow me to skip all of the example code I have, and simply use the same functionality that seems to be already built into the control.
So should I use example code that connects to the database, builds the query then runs it on the database, or is there a better way, using something already built into the DevExpress WinForms suite?
Thanks.
You can use Embedded Navigator controls to insert rows !
https://www.devexpress.com/Support/Center/Question/Details/Q235790
After some research, I found that the best way to interact with the data in the grid, or with any database for that matter, is to use DevExpress's eXpress Persistent Objects for .NET. Great bit of technology. It allowed me to specify the database and table I was interested in, and it created all of the plumbing to allow me to deal with rows in the table like normal C# objects with properties.
If you are struggling with trying to mix in SQL queries and the like into your application, I highly recommend you make your life much easier and use XPO.
Here is a link to the documentation describing XPO: http://documentation.devexpress.com/#XPO/CustomDocument1998

Advice on datastructure

I was looking for some advice on what options are possible to create an interactive table similar to the image below with C#4.0 WPF.
Essentially I want some fixed data displayed on the left and based on user input the remaining data recalcs based based on selections
I was thinking a datatable has about 95% of the functionality I need but I can't find many resources or info on adding controls to make it interactive or if what I'm considering is a dead-end.
I've currently got new datatables being generated based on selections elsewhere and displayed in Winforms DataGridView but it makes it difficult to compare so I really wanted to make it more interactive. For WPF I'd hoped there would be something nicer.
My questions are, can a datatable do this? Are there any better alternatives?
Additional Info:
The data doesn't come from a database, or a single source.
It doesn't need to be saved anywhere either
The columns and rows are not fixed
A DataGrid can of course do this for you, similar to WinForms DataGridView.
For the backend you have many choices but to accommodate runtime flexibility the good old DataTable might still be a good choice.
Probably link it through a CollectionViewSource

Database update after inserting rows into Dataset

I am a newbie to Database programming. After inserting a couple of rows into a DataSet object, I am trying to write back the updated DataSet to the Database but cannot figure out how to do it.
Can you give an example for the following please?
what SQL insert command to use if DataSet is already updated with new rows
Databinding example - especially considering an initially empty table in the DB
I am using SQLExpress 2008 & its C# WinForms application.
thanks
ps: I have already looked at the related questions here. This one is different in that I am first adding my new data into a DataSet and want to update the DB then.
What you need to do is configure a DataAdapter or TableAdapter object that contains the proper Update command. Then when you are done updating the rows in your DataSet, you can call DataAdapter.Update(DataSet) and it will do all the hard work for you.
Since you're starting out, I'd suggest looking at the TableAdapter objects that are built using the XSD schema tool. They allow you to simply drop your tables into the XSD to create a schema, and then let the wizard generate the appropriate SQL commands (it'll even do Stored Procedures for you) to handle all the CRUD work. I've been using these for a while and love them.
EDIT: In response to Sesh's request, Scott Gu has a great tutorial series on using the Table Adapters here. I wanted to post this in the answer so others can find it easily.

Categories