Execute a stored procedure inside textbox to get a localized text - stored-procedures

Is it possible to execute a stored procedure inside a textbox? We need this to localize our report.
For example, we have a stored procedure which returns the localized text for a given Key and a given LanguageId. I want to execute this stored procedure for every Label (Textbox) with a different key inside my report.
We are using SSRS 2008.

I think you've got things a little mixed up, you can't "execute a sproc inside a textbox".
What you can do instead, is create a dataset that gets all required Key/Value pairs for your current language, something like this:
EXEC usp_GetReportLabels 'en-US'
/* Returns:
Key Val
--------- ------------
lbl1 Firstname
lbl2 Surname
etc etc
*/
On your textboxes you can use an expression utilizing the Lookup Function to retrieve the correct row from that dataset, and display the label value.
Note: You mention ssrs-2008 but not the ssrs-2008-r2 edition, I don't think the Lookup function is available in plain-2008. In that case you'll need to restructure your dataset(s) a bit to get the same effect. One solution would be to PIVOT the dataset and make the Keys into columns (the dataset will only contain one row in that case, so you can do First(Fields!lbl1.Value)). Bit of a workaround though.

Related

Delphi Combo Edit from CSV File

I have an application that will load a CSV file containing two columns. At program load I need to have the first column as items in a combo edit control. Once the user selects (or enters a value) I need to populate a label with the value from the second column. My thought was to use an in memory data set, FDMemTable which would be loaded at form create. Then once the user selects, or enters an item, I would run a query to pull the description. I've tried but have been unsuccessful with the simple loading of the combo edit.
Is this the best way to achieve the desired results, and is there samples similar to what I'm looking to do?
Read the file.
Parse it into an array of name/value pairs.
Populate the combo drop down list with the names.
When the combo's selection is changed to a new index, read the value from the array using that index. Update the label.
Database tables and queries seem somewhat over the top for a single simple task like this.

Combine multiple columns containing similar values into one column for use in graph inside Crystal Reports

I have 3 fields, Action1, Action2 and Action3 contained in one report. Each Action field is selected from the same list of values. I would like to graph a count of these values by the value of the field and not field itself. I need one graph and not one graph per Action field. I have tried to combine the field values into an array in the details section, but the report shows the concatenated string values "Action1, Action2, Action3', as a single value in the graph. I tried to graph using "on change of", but it will only allow 2 fields and not 3. Is there a way to count these values regardless of the Action field where they are found?
I have been working with Crystal for years, but can't figure this out for whatever reason.
I was never able to find a solution to this issue inside of Crystal Reports itself. What I ended up doing was creating a stored procedure in SQL to use as the data source. In the stored procedure I basically performed a cross join such that there was only 1 Action returned per record. In CR I then was able to summarize the Action field values.

Delphi grid with a different data type in each row, displayed dynamically

I am trying to create a Delphi grid to allow display and edit in a db grid of data that might have a different data type on each row. I would like to display a specific control for each data type, e.g. when the data type is DateTime, I want to display my custom edit control that allows typing a date in or popping up a calendar.
The data looks something like this:
Name DataType DateValue StringValue BooleanValue
---------------------------------------------------------
A Date 1/1/2007
B String asdf
C Boolean True
...and in the db, this table has a column for each possible type of value. So, there is a BooleanValue column, DateValue, etc.
What I would like to do is display a single 'Value' column in the grid that displays the appropriate edit control depending on what the 'DataType' is for that row. So, the grid should look like :
Name DataType Value
---------------------------
A Date 1/1/2007
B String asdf
C Boolean True
It seems I will need to display a different edit control (to allow the user to edit the Value column) for each row dynamically based on the value of the DataType column. I know there are more advanced grids out there that handle this sort of problem, but the powers that be will not allow anything but what is available out-of-the-box with Delphi.
Any ideas on how to make something like this work?
Personally, I would not go for editing directly inside the TDBGrid in this case, since your Table is not DB normalized (I don't use it in any case actually). I would have used a Calculated field to display the desired value in the grid, And dynamically created the TDBxxxEdits on the form for each field type (How about your own TDBTreeEdit for example, a TDBRichEdit, or a DB Image pickup editor, etc...?).
In case you do want to use your own controls on the TDBGrid, and replace the default TInplaceEdit editor, you can refer the following article: Adding components to a DBGrid, and a related article: Displaying and editing MEMO fiels in Delphi's TDBGrid
Displaying all of the data in the same column is quite easy. You can simply add a calculated string field, and change the value according to what you are storing in that row.
The editing is quite a bit more complicated. If you want to have an in-place editor, you are in for a world of hurt... I've done it, it's a pain, and takes a lot of time. If you want to display a dialog to edit the value, that's much easier. You can add a column objects to the grid and you can setup the column you have attached to the calc field to display a button. When the button is clicked you simply display the editing dialog needed for that row, and commit the edits when the dialog is closed.
There are other ways to get this done, but I would say the above would be the shortest way. Other ways may include custom draw events to display your data in one column, intercept clicks to create your own editor, etc, etc, etc...
after add calculated fields .
Sample:
procedure OnCalculate(DataSet:TDataSet);
begin
case IndexText(DataSet['ValueType'],['Date','String','Boolean']) of
0:DataSet['DateValue']:=StrToDateTime(DataSet['Value']); // also converting
1:DataSet['StringValue']:=DataSet['Value'];
2:DataSet['BooleanValue']:= MatchText(DataSet['Value'],['1','True','T','Y','Yes']);
{etc datatypes}
end;
end;

Reporting Services - Determine whether or not Stored Procedure returns garbage fields

I have to develop a report against Sybase and I am calling a stored procedure for the dataset using an exec statement in a text query.
This stored procedure, instead of returning no records when there are none available, returns a table with a different column structure than that which is returned when records are available.
This causes all of my fields to display #ERROR. Is there a way to determine that the data set is going to return this garbage row so that I can hide the rows that are effected and handle the error?
Thanks so much for your help.
Frank
The solution for this is to check the IsMissing property on the dataset field:
Set the row's "Hidden" property to -
=IIF(Fields!FieldThatShouldBeThere.IsMissing,true,false)
Frank

Benefit of using DBComboBox over CombBox?

So I'm messing around with a new project in Delphi 2009 and the default components that can be dropped onto a form for accessing data consist of a SQLConnection, DataSource and SQLQuery. If I add a simple select to the query component, say:
select name from customers
and then drop a DBComboBox on the form and link it up with the DataSource I get a single record in the combo box. After using Google for half and hour to figure out what I was doing wrong it looks like you have to manually add some code to your project which loops through the dataset and adds all the records to the drop down box. Something like:
while not SQLQuery.eof do
begin
DBComboBox.items.add(SQLQuery.fieldbyname('name').asstring);
SQLQuery.next;
end;
And that actually sort of works, but then you get a list in the drop down which you can't actually select anything from. Regardless of the result though I'm wondering why would you even use a DBComboBox if you have to manually add the result of your query to it? Seems to me that if it doesn't automatically populate the db combo box with the result of the query then we might as well be using a non-data-aware component like tcombobox.
I guess what I'm asking is why does it work this way? Isn't the purpose of data aware drag-and-drop controls to minimize the amount of actual written code and speed development? Is there a method that I'm missing that is supposed to make this easier?
A TDBComboBox doesn't get its list of values from the database; it gets its current value from the database. Link it to a field in your dataset, and when you change the active record, the combo box's current value will change. Change the combo box's current value, and the corresponding field's value will change.
If you want to get the list of values from the database as well, then use a TDBLookupComboBox.
This is all covered in the help:
Using TDBListBox and TDBComboBox
Displaying and Editing Data in Lookup List and Combo Boxes
Defining a Lookup List Column
I think you want the TDBLookupComboBox because that allows you to lookup from a list of items where the list comes from a dataset.
In the TDBComboBox, the list is just a TStrings manually filled with data.
--jeroen
DbCombox is a dbaware version of the standard combobox component.

Resources