?
Solved

Using User Defined Functions With VB.NET & Crystal Reports

Posted on 2003-03-06
5
Medium Priority
?
337 Views
Last Modified: 2011-04-14
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
Comment
Question by:shr81
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 

Author Comment

by:shr81
ID: 8089825
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
 

Author Comment

by:shr81
ID: 8089929
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
 
LVL 16

Accepted Solution

by:
twalgrave earned 300 total points
ID: 8094577
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
 

Author Comment

by:shr81
ID: 8096691
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is about my first experience with programming Arduino.
Make the most of your online learning experience.
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…
Progress
Suggested Courses

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question