Imports CrystalDecisions.CrystalReports.Engine
Imports CrystalDecisions.Shared
Public Class Form8
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim CrTables As Tables
Dim CrTableLogonInfo As New TableLogOnInfo()
Dim CrConnectionIfo As New ConnectionInfo()
Dim rptDoc As New ReportDocument()
rptDoc.Load(Application.StartupPath & "\CrystalReport1.rpt")
With CrConnectionIfo
.ServerName = Application.StartupPath & "\Database2.accdb"
End With
CrTables = rptDoc.Database.Tables
For Each CrTable In CrTables
CrTableLogonInfo = CrTable.LogonInfo
CrTableLogonInfo.ConnectionInfo = CrConnectionIfo
CrTable.ApplyLogOnInfo(CrTableLogonInfo)
Next
If Not (String.IsNullOrEmpty(TextBox1.Text)) Then
Dim qry As String = TextBox1.Text.Trim().ToString()
Dim reportQuery As String = String.Empty
reportQuery = "{ใบเสร็จลูกค้า.หมายเลขเครื่อง} LIKE '*" & qry & "*'"
reportQuery &= "OR {ใบเสร็จลูกค้า.วันที่} LIKE '*" & qry & "*'"
reportQuery &= "OR {ใบเสร็จลูกค้า.สินค้าและบริการ} LIKE '*" & qry & "*'"
reportQuery &= "OR {ใบเสร็จลูกค้า.ดำเนินการ} LIKE '%" & qry & "%'"
reportQuery &= "OR {ใบเสร็จลูกค้า.รวมเงิน} LIKE '%" & qry & "%'"
CrystalReportViewer1.SelectionFormula = reportQuery
End If
CrystalReportViewer1.Refresh()
CrystalReportViewer1.RefreshReport()
End Sub
Dim objConn As New SqlConnection
Dim objCmd As New SqlCommand
Dim dtAdapter As New SqlDataAdapter
Dim ds As New DataSet
Dim dt As DataTable
Dim strConnString, strSQL As String
strConnString = "Data Source=" & Cnnt.StrServer & ";Initial Catalog=" & Cnnt.StrDatabase & ";User ID=" & Cnnt.StrUser & ";Password=" & Cnnt.StrPWD
strSQL = "select * from Book"
objConn.ConnectionString = strConnString
With objCmd
.Connection = objConn
.CommandText = strSQL
.CommandType = CommandType.Text
End With
dtAdapter.SelectCommand = objCmd
dtAdapter.Fill(ds, "Data_Book_New")
dt = ds.Tables(0)
dtAdapter = Nothing
objConn.Close()
objConn = Nothing
Dim rpt As New rptReport_Book_by_Type()
rpt.Load()
rpt.SetDataSource(dt)
Me.CrystalReportViewer1.ReportSource = rpt
Dim rpt As New rptReport_Book_by_Type()
rpt.Load()
Date :
2019-03-19 08:51:10
By :
outhai
No. 5
Guest
Code (VB.NET)
'C:\YourProgram\bin\Debug\abcd.exe
'C:\YourProgram\CrytstalReport1.rpt
If Application.StartupPath.EndsWith("bin\Debug") Then
rptDoc.Load(Application.StartupPath & "..\..\CrystalReport1.rpt")
ElseIf Application.StartupPath.EndsWith("bin") Then
rptDoc.Load(Application.StartupPath & "..\CrystalReport1.rpt")
Else
rptDoc.Load("C:\YourProgram\CrytstalReport1.rpt")
End If