|
-
Sep 13th, 2006, 04:59 AM
#1
Thread Starter
Member
[RESOLVED] Database ,Crystal Reports, anb Vb.Net 2005
Hi ,
I have a report, that thake the information about c:\myprogram\data.mdb ,
the problem, is that the user can choice another database ,but always my report ,that data from c:\myprogram\data.mdb.
All that i can do is change from ,click crystalreport1.rpt, after ,right button ,data base ,and choice database.
But how i can change from code?
Thanks
-
Sep 13th, 2006, 05:18 AM
#2
Junior Member
Re: Database ,Crystal Reports, anb Vb.Net 2005
Use
Cr.Datasource with Data Controls on From or
Cr.Connect with ODBC Connection String
-
Sep 13th, 2006, 09:54 AM
#3
Thread Starter
Member
Re: Database ,Crystal Reports, anb Vb.Net 2005
Sorry but i can't find it.
In my program ,i have a report called crystalreport1.rpt ,and if in my form code ,i put crystalreport1. enable evenlog ,equals and referenceequals ;and if i put crystalreport11. i can see clone,close ,database ...
but anywhere Datasource or connect ,how i can fix it?
Thanks
-
Sep 18th, 2006, 04:30 AM
#4
Thread Starter
Member
Re: Database ,Crystal Reports, anb Vb.Net 2005
Hi ,does anybody can help me?
-
Sep 18th, 2006, 07:38 AM
#5
Re: Database ,Crystal Reports, anb Vb.Net 2005
This is waht we use (VB 2005 and CR11):
VB Code:
Public strReport As String
Public strSelect As String
Public param As String
Private Sub frmReportView_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
ViewReport(strReport, strSelect, param)
End Sub
Friend Function ViewReport(ByVal sReportName As String, Optional ByVal sSelectionFormula As String = "", Optional ByVal param As String = "") As Boolean
Dim intCounter As Integer
Dim intCounter1 As Integer
Dim objReport As New CrystalDecisions.CrystalReports.Engine.ReportDocument
Dim ConInfo As New CrystalDecisions.Shared.TableLogOnInfo
Dim paraValue As New CrystalDecisions.Shared.ParameterDiscreteValue
Dim currValue As CrystalDecisions.Shared.ParameterValues
Dim mySubReportObject As CrystalDecisions.CrystalReports.Engine.SubreportObject
Dim mySubRepDoc As New CrystalDecisions.CrystalReports.Engine.ReportDocument
Dim strParamenters As String = param
Dim strParValPair() As String
Dim strVal() As String
Dim index As Integer
Try
Me.Cursor = Cursors.WaitCursor
objReport.Load(Application.StartupPath & "\" & strReport)
intCounter = objReport.DataDefinition.ParameterFields.Count
If intCounter = 1 Then
If InStr(objReport.DataDefinition.ParameterFields(0).ParameterFieldName, ".", CompareMethod.Text) > 0 Then
intCounter = 0
End If
End If
If intCounter > 0 And Trim(param) <> "" Then
strParValPair = strParamenters.Split("&")
For index = 0 To UBound(strParValPair)
If InStr(strParValPair(index), "=") > 0 Then
strVal = strParValPair(index).Split("=")
paraValue.Value = strVal(1)
currValue = objReport.DataDefinition.ParameterFields(strVal(0)).CurrentValues
currValue.Add(paraValue)
objReport.DataDefinition.ParameterFields(strVal(0)).ApplyCurrentValues(currValue)
End If
Next
End If
ConInfo.ConnectionInfo.UserID = "HAPPY"
ConInfo.ConnectionInfo.Password = "GILMORE"
ConInfo.ConnectionInfo.DatabaseName = "XMEN"
For intCounter = 0 To objReport.Database.Tables.Count - 1
objReport.Database.Tables(intCounter).ApplyLogOnInfo(ConInfo)
Next
For index = 0 To objReport.ReportDefinition.Sections.Count - 1
For intCounter = 0 To objReport.ReportDefinition.Sections(index).ReportObjects.Count - 1
With objReport.ReportDefinition.Sections(index)
If .ReportObjects(intCounter).Kind = CrystalDecisions.Shared.ReportObjectKind.SubreportObject Then
mySubReportObject = CType(.ReportObjects(intCounter), CrystalDecisions.CrystalReports.Engine.SubreportObject)
mySubRepDoc = mySubReportObject.OpenSubreport(mySubReportObject.SubreportName)
For intCounter1 = 0 To mySubRepDoc.Database.Tables.Count - 1
mySubRepDoc.Database.Tables(intCounter1).ApplyLogOnInfo(ConInfo)
Next
End If
End With
Next
Next
If sSelectionFormula.Length > 0 Then
objReport.RecordSelectionFormula = sSelectionFormula
End If
crViewer.ReportSource = Nothing
crViewer.ReportSource = objReport
crViewer.Zoom(1)
crViewer.Show()
Application.DoEvents()
Me.Text = sReportName
MyBase.Visible = True
Me.BringToFront()
Return True
Catch ex As System.Exception
MsgBox(ex.Message)
Finally
Me.Cursor = Cursors.Default
End Try
End Function
Sometimes the Programmer
Sometimes the DBA
Mazz1
-
Sep 18th, 2006, 09:20 AM
#6
Thread Starter
Member
Re: Database ,Crystal Reports, anb Vb.Net 2005
Hi ,firts thanks for your help,
Some questions:
1)
Public strReport As String --> Is the name of my report file, ej: Crytal.rpt
Public strSelect As String --> String sql ,ej: select * from table
Public param As String ---> ???
2)
My database ,doesn't have password ,so what i have to put here?
ConInfo.ConnectionInfo.UserID = "HAPPY"
ConInfo.ConnectionInfo.Password = "GILMORE"
ConInfo.ConnectionInfo.DatabaseName = "XMEN"
3)
I tyed viewrerport ("C:\name.rpt") and i get "Can't load this report") ,what's wrong?
----------
Thanks a lot for your help again
-
Sep 18th, 2006, 09:31 AM
#7
Re: Database ,Crystal Reports, anb Vb.Net 2005
Public strReport As String --> Is the name of my report file, ej: Crytal.rpt Yes
Public strSelect As String --> String sql ,ej: select * from table This is a condition statement (report selection cretieria for us)
Public param As String ---> ??? Used for parameters in a report.
Just don't use the username and password fields. The database name would be the full path to your db.
Sometimes the Programmer
Sometimes the DBA
Mazz1
-
Sep 18th, 2006, 09:49 AM
#8
Thread Starter
Member
Re: Database ,Crystal Reports, anb Vb.Net 2005
thanks ,works fine !!!!!!
-
Sep 18th, 2006, 11:53 AM
#9
Re: Database ,Crystal Reports, anb Vb.Net 2005
Your welcome. If this resovles this issued please mark the thread as RESOLVED using the thread tools in the menu.
Sometimes the Programmer
Sometimes the DBA
Mazz1
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|