Click here to Skip to main content
15,895,011 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Please tell me how can I make connection with crystal report by code or when I use wizard.
Also, How can I change that sql 2000 to sql express?
Posted
Updated 24-Oct-10 19:39pm
v2
Comments
Sandeep Mewara 25-Oct-10 1:40am    
Question subject is meant to be a title kind of for your question and not the question itself. Please use body of the question for full detail.
Anne Nyberg 25-Oct-10 10:17am    
Hi,
First you need a report in your solution and design it the way you want it.
Private m_crAvstamning As CRAXDRT.Report

The following code is from when the user clicks on a menu to show a report already created.

Private Sub mnuReportAvstamning_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles mnuReportAvstamning.Click
Dim sDate As String
Dim f As Object

On Error GoTo Err_mnuReportAvstamning_Click
frmGetDate.ShowDialog()
If frmGetDate.DialogResult = Windows.Forms.DialogResult.OK Then

sDate = Replace(frmGetDate.mdDatum, "-", "")
frmGetDate.Close()

crApp = New CRAXDRT.Application
m_crAvstamning = crApp.OpenReport(Application.StartupPath & "\avstamning.rpt")

For Each f In m_crAvstamning.FormulaFields
With f
f.Text = ""
End With
Next

If Not m_crAvstamning.Database.Tables(1).TestConnectivity Then
m_crAvstamning.Database.Tables(1).ConnectBufferString = objConnector.GetConnectionString
End If

m_crAvstamning.Database.Tables(1).Location = mDatabase & ".dbo.KNBS503"

m_crAvstamning.FormulaFields(1).Text = "'" & System.DateTime.Now.ToShortTimeString & "'" 'ABE Now var Time
m_crAvstamning.FormulaFields(2).Text = "'" & Environ("computername") & "'"

m_crAvstamning.ParameterFields(1).ClearCurrentValueAndRange()
m_crAvstamning.ParameterFields(1).AddCurrentValue(mTeam)
m_crAvstamning.ParameterFields(2).ClearCurrentValueAndRange()
m_crAvstamning.ParameterFields(2).AddCurrentValue(sDate)

m_crAvstamning.Database.AddOLEDBSource(objConnector.GetConnectionString, "KNBS500;1")
frmShowReport.Show()
frmShowReport.ShowReport(m_crAvstamning)
End If
Exit_mnuReportAvstamning_Click:
Exit Sub

Err_mnuReportAvstamning_Click:
'MsgBox Err & " " & Error
Resume Exit_mnuReportAvstamning_Click
End Sub

Hope it helps you.
/Anne

1 solution

Very nice article for you which covers creating Crystal reports with VB.NET & SQL Server.

Introductions to Crystal Reports in .NET[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900