DevExpress report Main and Detail reports stored procedures - c#

I have to create an XtraReport with two sections; master and detail. For example, categories - is master and their products is detail:
Category1
Prod1
Prod2
Prod3
Category2
Prod4
Prod5
Prod6
The problem is that both categories and relevant products come from Stored Procedures. So I have 2 stored procedures, the first master stored procedure is without parameters, the second detail store procedure has the parameter of CategoryId (that comes from first Stored Procedure).
I can't find a way to set the CategoryId parameter value of the second stored procedure from the first stored procedure.
In the stored procedure designer I can see this, but I can't set the parameter value to first store procedure ID.

The solution is using xsSubreport component, create separate sub-report and attach to it.
You can pass parameters to it from outer(main) report, and it will fetch data in it based on outer parameters
https://www.youtube.com/watch?v=ZKRsXxjr_EI

I know I'm being a little late on this, but I'm sure that the DevExpress built-in data access solution (the EFDataSource component) does not support this kind of integration as the entire source is filled at once. As I understand, you need to create a Master-Detail Report. In this case, the best option here will be to define control bindings in Object Binding mode, and then, at runtime, execute both stored procedures manually using your DBContext class. Assign the first result set directly to XtraReport.DataSource. The second stored procedure should be executed at runtime several times in the DetailReportBand.BeforePrint event handler. You can get the master row's CategoryId as rootReport.GetCurrentColumnValue("CategoryID")
I hope this helps. If my explanation is not clear, I'm sure the DevExpress support team will be happy to explain more and provide you with an example (not sure why you've not done that in the first place though — StackOverflow is not meant for discussing vendor-specific products)

Related

How to display a search result in a treeview

Currently, I'm working in a MVC project (this is my first project). I'm doing fine but I'm stuck somewhere. I hope someone will help me out with this.
In this project I have to search for a record (with id) in SQL database from visual studio, where I should get result in a treeview... like under ID we may have a lot of sub ids or may not, if we have one sub id, it should display one if we have multiple sub ids multi-level treeview should display.
Note: This result I should get from the database when the user searched for particular id only, DATA from the database should not be loaded with the page.
Create a tree view using css and html. Populate the value using a rest controller or controller.
create an arraylist which returns your search result.
return the value from the list to a model or a url using a function.
As you can see there are many ways you can do this.
you can check this out as well: https://www.c-sharpcorner.com/UploadFile/85ed7a/searching-records-from-database-and-display-in-gridview-and/
and for only loading id from the database you can run
Select id From tablename
and if you want the details only after user clicks the id
Select * From tablename Where id = clickedvalue
you could also use where statement in sql to have more specific values
you'll need to change few codes as this tutorial uses grid view.
i hope this helps. But please provide some code snippets of what you've done or where you're stuck to get a precise answer.

Effective way of displaying results of stored procedure with interactive button columns

Apologies if the title is vague - I will explain in as much detail as possible the problem.
I have an ASP.NET webpage which queries a TSQL database using a stored procedure, the query is run on Page_Load. The procedure returns a dataset (with ID column, RequestID). The contents are essentially a list of data-specific requests that need to be approved or rejected as exceptions to another workflow (not entirely relevant but may help explain my approach)
I'd like to display the results of this procedure in a grid (currently this is easy enough) however I'm running into problems when trying to add buttons that allow the user to interact with the data, e.g. I'd like 'Reject/Approve' buttons.
When one of these buttons is pressed the relevant stored procedure would be run, with the RequestID of the row pressed passed as a parameter. The idea is to have the stored procedure update an audit log and update the relevant tables accordingly (each request represent a complex data object spanning multiple tables) - for this reason the default controls aren't sufficient for select/edit/delete.
I feel like I'm doing this entirely wrong from the basic approach, which is using a gridview and trying to add custom SelectMethod/DeleteMethod's. What would be a best practice approach for doing this?
EDIT*
Here is the data table and how i'm populating it:
DataTable Requests = new DataTable();
Requests = GetRequests(connString); //Method that returns a datatable from a stored procedure
Displaying the data in a gridview as follows:
gridView.DataSource = Requests;
gridView.DataBind();
However when i add the following code, which is me trying to fire a custom method when using the default select/delete controls in a gridview i get an exception:
gridView.AutoGenerateDeleteButton = true;
gridView.AutoGenerateSelectButton = true;
gridView.SelectMethod = "ApproveRequest";
gridView.DeleteMethod = "RejectRequest";
Here is the exceptiopn (which make sense, but makes me think i'm going about this the wrong way).
Message=DataSource or DataSourceID cannot be defined on 'gridView' when it uses model binding.

High performance Custom user fields

looking for examples/tutorial for custom user fields, not via EAV
EAV is going to be problematic for various reasons such as performance
there are many base entities/tables with over 100000 records each
there will likely be over a dozen attributes
the records are to be displayed in a flat ui grid incl. custom fields so flattening them would be an issue while maintaining performance
Looking at enabling this via DDL where all custom fields would go into a matching table such as
<tablename>_custom_<userid>
and all user attributes would map to a column each and all their metadata stored in a metadata table
the retrieval would be simpler where the query would simply be
select *
from <tablename> A, tableName_custom_userid B
where B.KeyField = A.KeyField --( perhaps using outer join, haven't gone that far yet )
Wondering if there are any gotchas down the road that i need to be aware of ?
of course any samples/pointers would be helpful to kickstart the effort
specifically would appreciate any advice on using DDL for Sql Server compact 4
One technique I have seen used is to use a sort of 'hard-coded' EAV pattern. Don't hang up! It worked well with the dataset sizes you were talking about and didn't actually use EAV - it was only EAV-esque.
The idea is to have a set of tables to store these custom attributes within it, with some triggers (described below) on them. The custom attributes tablesets store metadata about the attribute (what table it goes with, data type, constraints, etc). You can get very fancy with this but I did not haev the need.
The triggers on your meta-tables are there to re-generate views that rollup base+extension into first class objects within the DB. So instead of table person + employee extension table, you have an employee view that includes both. When you drop a new value into the custom attributes tables, the triggers will re-roll the views and include the new stuff. If you wanted to go nuts, you could also have the triggers re-write stored procedures as well. Depending on how your mid-tier code is structured, you would still be forced to re-code some, however this would be the case anyway should you be applying rules that read the data.
In testing, I found that for the relatively small # of records you're talking about, performance was somewhat slower but followed roughly the same pattern of degradation (2x the number of records, ~2x as slow).
-- edits --
How I saw it done, you had a table that represented your first class objects, so a row for 'person' and a row for 'employee,' etc. We'll call that FCO. Then you had a secondary table that stored what tables represented the FCO. We'll call that Srcs.. For person, there would be one row, which is the person table. For Employee, there would be two rows, the person table and the Employee extension. There is a third table, called Attribs, which stores the columns from the tables that constitute the FCO. For simplicity, we'll say Employee has ID, Name and Address, and Employee has Hire Date and Department, and obviously PersonID referring back to Person table. So, 2 rows in FCO table (person and employee), 3 rows in Src table, 8 rows in Attribs.
The view, we'll call it vw_Employee, selects PersonID, Name, Address, Hire Date, Department from the two tables. It is built by a SQL stored procedure we'll call OnMetadataChange.
This SP is fired (by trigger or batch process), and its purpose is to generate the CREATE VIEW statements. It will iterate through every First Class Object, collect which fields from which tables constitute the view, and will issue a CREATE statement based on that. So OnMetadataChange produces a DROP and CREATE for each view, it generates a dynamic SQL statement that is executed once per entry in FCO table. It is preferable to do this with Triggers but not necessary. Hopefully your FCO definitions won't change too often, and when they do, there will probably be a code release as well. You can run your OnMetadataChange SP at that time.
The end result is a 2-layer database. The views constitute the First Class Object layer, which is meaningful to the application. The application only uses views. The tables constitute the 'physical' layer, which the application shouldn't care about. The meta-tables are essentially your mapping between the FCO layer and the physical layer. It takes some time to set it up, but it's quite effective, and gives you many of the benefits of EAV, while at the same time giving you the concrete benefits of 3nf tables (indexability, etc).
If you'd like I can throw some sample SQL out there.
Part of the problem you are having is that you are trying to store schema-less data in a SQL database, which is not its strength. There are three approaches that would make your life far easier:
1) Have a column which stores the serialized custom fields, with whatever format is mst convenient. For example, this column could store xml. Upsides are that you can use SQL Server Compact and pulling back a record is trivial. Downsides are that you always have to pull/push the entire xml blob to do an update, and it is difficult to impossible to query on any custom fields.
2) Upgrade to SQL Server Express, and use XML columns. This is nearly the same as the first suggestion, except that any server ready version of SQL Server has native support for XML data. These columns can have indexes added and fields within the data can be used in queries.
3) Use a Schema-less Database, like MongoDB or CouchDB. These databases are all about storing schemaless data, so your custom fields will be no different than any other field. As such, you can index and query custom fields. Upsides are that custom data is incredibly easy to work with, downsides are that you would have to spend some time rethinking how you store data to fit within their model.
If you do not need to query based on custom fields, or if you can query custom fields within business logic, then the first option can work for you. In any other case, I would err towards something with more capabilities than compact. If cost is the deciding factor, both SQL Server Express and MongoDB are free.

Entity Framework and MySql Stored Procedures

I am working with Entity Framework 4.0, VS 2010, MySql server database, and mysql-connector-net-6.4.4 for connection purpose. It works fine, that said, it can generate Model classes, csdl, ssdl etc files well. But, for stored procedures it doesn't work.
Here is what happens..
Right clicked on an SP from Model Browser, select [Add Function Import]. This opened a dialog box
Filled appropriate values like, Function Import Name, Stored Procedure Name
Click on [Get Column Information]. This results into some Grid filled up at the bottom of this button. In the grid, there is a column named [EDM Type]. This column shows [Not supported] due to some unknown reason :(
Now, clicked on [Create New Complex Type]. This goes OK, without Error
Now, clicked on OK button
After doing all above steps, there is no Complex Type created in the code however, which is the problem.
Can anyone please help?
The generated Complex Type is in the Complex Types folder in the Model part of the Model Browser.
To access ti in code, use it as any other Entity
MyComplexType ct = new MyComplexType();
And you can use it as a result type for your stored procedure:
List<MyComplexType> info = ctx.GetAllEmployees().ToList<MyComplexType>();
You must ensure that the GridView's columns mappings match the Complex Type's properties, or that the GridView's property AutoGenerateColumns is set to true.

getting multiple sets of data in one request?

I am working on a site in which as user logs in (first database request) the stored procedure varify password and user id and then returns user record that I put in session to use next.
After this I do a second db request. it returns addresses of user which I put in cache.
Can you pleas guide me is there some way that I can get both sets of data (user record and his address from 2nd table) in one database requests.
plz guide me on this, I am using DAAB (enter prise library) for data access.
Thanks
Modify your SP which has multiple select statements, as in you case is 2. Two select statements in one SP will return two record sets. Verify in SQL Management Studio, when you run your SP, it should show you multiple Grid in bottom panel.
Once your SP is done, call SP from C# code and load result in DataSet. Dataset will have two table, and you can get the data from different table
You can write two select queries in a stored procedure or
Execute two queries one after another . In single query you can execute and receive the data in DataSet .
ExecuteDataset()
So two tables will be returned inside the dataset . You can get the values like
dataset.tables(0)
dataset.tables(1)
Thanks
You would gain nothing from retrieving two results sets in one go, But the code will become more incoherent. Why do you thing you need to merge two logically separate operations into one? Instead of using such questionable methods you can use join to get one result set that contains all the data in one go, but still that seems wrong. I can not see a clean way of doing what you are asking for and any benefits that might be gained.

Categories