Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 371
  • Last Modified:

Using User Defined Functions With VB.NET & Crystal Reports

First off, this is my first dealing with Crystal Reports, so I'm sorry if I'm not too clear on some of my description.

I have a user defined function in SQL Server 2000 that I need to access in a crystal report.
The function has three parameters and returns a table.

The function shows up as a stored procedure when I make a new report, but gives an error.  I can set it up as a command, and type out the SQL myself - then I supply static parameters, and the report looks great.

My question is how do I make this dynamic?  I have values in VB.NET that I want to use as the arguments to my user-defined function, but can't find a good way to add this to my command in Crystal Reports.

Thanks!
(sorry for the point value - I've seen responses from here a lot so I decided to try; I still need to get more points to award though.)
0
shr81
Asked:
shr81
  • 3
  • 2
1 Solution
 
shr81Author Commented:
Thanks twalgrave!  I had seen some of those before, but I hadn't seen the search engine yet.

Unfortunately I'm still havign some trouble with this though.  I'm pushing my way through Crystal Reports' site and the MSDN documentation, but for some reason this isn't working with what I'm trying to do.

Here's a more detailed description...

I need to make a report that is a timesheet for an employee.  The user chooses an employee and a date range for the report.

The output needs to be slightly different than how it is stored in the database, so I have a user-defined function in SQL Server 2000 (which returns a table) defined as:
fn_tblTimesheet(@dtStart datetime, @dtEnd datetime, @lastSSN varchar(4))

This function shows up in the stored procedures list in Crystal Reports, but gives a "Not Supported" error when I try to verify it.  Also, it doesn't recognize any parameters for it.

I tried adding a command, with the text "SELECT * FROM dbo.fn_tblTimesheet('2/1/03', '2/28/03', '0000') AS t" and this worked; however, I can't seem to replace the fixed values I fed it with parameters.

Eventually I tried creating a stored procedure to see if it could work that way, the the stored procedure just ran the function.  When I do this, Crystal Reports will recognize three parameters and their types, but still gives a "not supported" error when I try to verify.  If I create a command I can give fixed values and it will run fine.

Of course, if I can't get it to verify these functions, it won't let me display any of their fields.  I'm still looking through documentation for a solution or to find a workaround, but if anyone has had a similar problem before and can help me out with this it would be very... well, helpful.

Thanks!
0
 
shr81Author Commented:
Thanks twalgrave!  I had seen some of those before, but I hadn't seen the search engine yet.

Unfortunately I'm still havign some trouble with this though.  I'm pushing my way through Crystal Reports' site and the MSDN documentation, but for some reason this isn't working with what I'm trying to do.

Here's a more detailed description...

I need to make a report that is a timesheet for an employee.  The user chooses an employee and a date range for the report.

The output needs to be slightly different than how it is stored in the database, so I have a user-defined function in SQL Server 2000 (which returns a table) defined as:
fn_tblTimesheet(@dtStart datetime, @dtEnd datetime, @lastSSN varchar(4))

This function shows up in the stored procedures list in Crystal Reports, but gives a "Not Supported" error when I try to verify it.  Also, it doesn't recognize any parameters for it.

I tried adding a command, with the text "SELECT * FROM dbo.fn_tblTimesheet('2/1/03', '2/28/03', '0000') AS t" and this worked; however, I can't seem to replace the fixed values I fed it with parameters.

Eventually I tried creating a stored procedure to see if it could work that way, the the stored procedure just ran the function.  When I do this, Crystal Reports will recognize three parameters and their types, but still gives a "not supported" error when I try to verify.  If I create a command I can give fixed values and it will run fine.

Of course, if I can't get it to verify these functions, it won't let me display any of their fields.  I'm still looking through documentation for a solution or to find a workaround, but if anyone has had a similar problem before and can help me out with this it would be very... well, helpful.

Thanks!
0
 
twalgraveCommented:
Passing parameters via Crystal Reports shoul dbe easily handled.  Unfortunately, I cannot test your issues as I do't have your DB.  There is always a work-around and that is to let Crystal Reports handle the conversion.  You do this by creating a CR function.  You can do this in either Crystal Syntax or in VB Syntax.  Simply format and manipulate the original field(not the stored proc).  One more alternative is to create a view on SQL Server that uses the Results of the sotred proc and call it from Crystal.
0
 
shr81Author Commented:
Thanks again twalgrave!  I actually didn't realize you could do that with views, I'll have to look into it.

The problem I was apparently running into was that since the table didn't actually exist (it was only created on the fly) Crystal Reports wouldn't recognize that it existed unless it had specific values.

I ended up creating an empty table in the database, and instead of having a function return a table,  I just clear the table and then repopulate it (I changed the function into a stored procedure).  In the code, I call this stored procedure to make sure the table has the values I want, then run the Crystal Report.

Sounds like the views method may have been less roundabout (I'm sure I could have done it directly in Crystal Reports as you suggested, but I had just figured out the syntax to do it from SQL server and didn't want to have to re-write it already :)).

I'll award points to your second comment.  Thanks for responding!
0

Featured Post

[Webinar] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now