Showing posts with label crystal. Show all posts
Showing posts with label crystal. Show all posts

Tuesday, March 27, 2012

Calling store procedure in Report throu VB

Dears
How to call store procedure in Crystal Report through VISUAL BASIC. i have Sp which has 3 parameters one is string others are dates parameter ,
how to to in the visual basic coding.
can any one help me passing paramerters .
Thanks
AnnuFor Vb 6:

Get rs (Recordset) calling stored procedure with parameters

After:

Dim report As CRAXDRT.report

Set report = crystal.OpenReport(App.Path & _
IIf(Right(App.Path, 1) = "\", "", "\") & _
s_Rpt & GetAdditionalNamePart(s_Rpt) & ".rpt") 'OPEN REPORT

report.Database.LogOnServerEx _
"crdb_odbc.dll", _
c_Settings.GetVal(CRYSTALDSN), _
c_Settings.GetVal(DBNAME), _
c_User.Name, _
c_User.Password, , _
c_Db.ConnectionStr
report.DiscardSavedData 'CLEARS REPORT SO WE WORK FROM RECORDSET
report.Database.SetDataSource rs 'LINK REPORT TO RECORDSET

Load frmReport
'ShowSendButton s_Rpt, frmReport.crV, frmReport.cmdSend

'crV - crystal viewer control
frmReport.crV.ReportSource = report 'LINK VIEWER TO REPORT
frmReport.crV.ViewReport

Best,

ika|||This is using VB 6 and CR 8.5 with RDC...

You can get your data from the Stored Proc through ADO and then pass the ADO recordset to Crystal:

'dsrReport is the name of your dsr file
Dim Report As New dsrReport

Set cmdData = New ADODB.Command
Set rsData = New ADODB.Recordset
cmdData.ActiveConnection = cnConnection
cmdData.CommandText = "sp_StoredProcName"
cmdData.CommandType = adCmdStoredProc
cmdData.Parameters.Refresh
cmdData.Parameters("@.Param1") = strParam1
cmdData.Parameters("@.Param2") = dtmParam2
cmdData.Parameters("@.Param3") = dtmParam3

'Required for RecordCount to return an accurate count
rsData.CursorType = adOpenDynamic
rsData.CursorLocation = adUseClient
rsData.Open cmdData

If Not rsData.EOF Then
Report.DiscardSavedData
Report.Database.SetDataSource rsData, 3, 1
End Ifsql

Tuesday, March 20, 2012

Calling Crystal Report From VB.Net

I want to execute my crystal report caling code on button click event in Vb.net, how can i proceedi think looking for this (http://www.dev-archive.com/forum/showthread.php?t=354022)

Sunday, March 11, 2012

Calling a Stored Procedure from Crystal Report

I've tried to find this documented on the Internet and found Crystal Reports User's Guid online documentation (582 pages of it!) It looks like it will be helpful for my other questions, but what I'm trying to do right now is call a stored procedure from my crystal report. So in Field Explorer under Database Fields my stored procedure is there with the three columns it selects. How do I put these three columns on my report? I try dragging them to Section 3 details and they're there but when I preview the report all I get are the headers, not the records. Is there something else I need to do? It requires an input parameter which I am not getting prompted for - maybe that is my problem, without an input parameter it can't successfully run the stored procedure, so how do I make it prompt me?

Thanks for helping me with my first Crystal Report!I've tried to find this documented on the Internet and found Crystal Reports User's Guid online documentation (582 pages of it!) It looks like it will be helpful for my other questions, but what I'm trying to do right now is call a stored procedure from my crystal report. So in Field Explorer under Database Fields my stored procedure is there with the three columns it selects. How do I put these three columns on my report? I try dragging them to Section 3 details and they're there but when I preview the report all I get are the headers, not the records. Is there something else I need to do? It requires an input parameter which I am not getting prompted for - maybe that is my problem, without an input parameter it can't successfully run the stored procedure, so how do I make it prompt me?

Thanks for helping me with my first Crystal Report!
This seems like a question for a Crystal Reports forum. When you do find the right forum to post to, it would surely be very helpful to mention the version of Crystal and the front-end you are using (I'm guessing the designer, but it could be the Crystal Web server you're talking about, etc).

Older versions of the Crystal Report designer had some hiccops when interfacing to Stored Procedures (that is, as opposed to Views and Tables that it has no problems with). I don't know about the newer ones since I only have versions 8 and 9, but I do use Stored Procedures successfully and can tell you that getting the prompts to pass to the SP isn't obvious (beyond what I'm prepared to describe here), particularly if you're using subreports. The Crystal web site has a wealth of sample code, but their search engine sucks (it never seems to find something unless you know exact titles to search for) and I'd suggest using Google Advanced Search and restrict results to their site only - works great.

I would suggest defining the SP with all the input parameters you want then use the Crystal Report wizard to auto-build a new report, and therefore the interface. You can do that with a sample report to explore what it did and try implementing that into your current report, or just start from scratch.

Also beware - they don't handle passing dates to SPs properly, so you have to enter it as a text field and do a conversion within the stored procedure.

I'll go out on a limb and assume that you are either using a date parameter, or you will need to in the near future. Here's some code for passing the date:

CREATE PROCEDURE sp_MySP (@.strAsOfDate varchar(8)) AS --use format 'YYYYMMDD' to represent the date as a string.

declare @.AsOfDate datetime
set @.AsOfDate = CONVERT(DATETIME, @.strAsOfDate, 112)

/*
my query ... WHERE MyDateColumn <= @.AsOfDate
*/
GO|||vich,
Yes, I know I am probably in the wrong place. I should've realized there would be a forum for Crystal but I started in a db forum since that's what I am used to.
I am using vb.net/Visual Studio 2005 and I created a crystal reports project in my solution where my app resides that needs to display the report. I realized re-reading my post that a reader would have no idea what environment I was using!
I've written the stored procedure successfully, I just need to know how to call it. I wrote the same code in a query, I guess it's called a Command by Crystal, and it works but eventually it should be moved to a stored procedure for performance. Thank you for the advice on dates, as I will need to report on a range such as this week, Sunday 8/5 to Saturday 8/11 or last year, etc.
Right now I can run my report directly in VS, but I want to have a button one one of my Windows Forms to run the report. So I am asking around about how to do that. My app is a Windows App using Web Services.
Thanks. I am as confused as I sound.

Tuesday, February 14, 2012

Calculating Luhn Digit in Crystal Reports

I have an 18 digit number and i need a SQL formula in Crystal Reports to calculate the Luhn digit.

Below is how Luhn is calculated.

Step 1: Double the value of alternate digits beginning with the first right hand digit.

e.g 8 6 3 7 5 = 8 12 3 14 5

Step 2: Add the individual digits compromising the products obtained in Step 1 to each of the unaffected digits in the original number.

e.g 8 12 3 14 5 = 8+1+2+3+1+4+5 (total=24)

Step 3: Subtract the total obtained in Step 2 from the next higher number ending in 0.

e.g 24 = 30-24 = 6 (Luhn = 6!)

Any help here would be fantastic!!This should do it...

Local StringVar sValue := {test.NUMBER};

Local NumberVar nSubtotal;
Local NumberVar i;

For i := (Length(sValue) - 1) To 1 Step -2 Do
(nSubtotal := nSubtotal + CDbl(sValue[i]));

For i := Length(sValue) To 1 Step -2 Do
nSubtotal := nSubTotal + (If CDbl(sValue[i]) < 5
Then CDbl(sValue[i]) * 2
Else
CDbl(sValue[i]) - (9 - CDbl(sValue[i])));

nSubtotal Mod 10;