'Insert this code in a button (Print Button)
Dim Querry1 As String = "SELECT Item_ID,Item_Name,Price,Quantity,Sum_Total From tblCart Where TransID = '" & TransID.Text & "'
SQL.runQuery(Querry1)
Dim rptDocs1 As ReportDocument
Dim connection As New ConnectionInfo()
Dim crtableLogoninfos As New TableLogOnInfos
Dim crtableLogoninfo As New TableLogOnInfo
Dim CrTables As Tables
Dim CrTable As Table
'Create RPT name it "Order.rpt" using Crystal Report
rptDocs1 = New Order
rptDocs1.Load(Application.StartupPath + "\Order.rpt")
'Replace the value of DatabaseName,ServerName,UserID,Password with your own SQLdatabase
With connection
connection.DatabaseName = "OnlineShop" 'myDataBase
connection.ServerName = "Server\MSSQLSERVER" '127.0.0.1
connection.UserID = "Admin" 'root
connection.Password = "123456" '12345
End With
CrTables = rptDocs1.Database.Tables
For Each CrTable In CrTables
crtableLogoninfo = CrTable.LogOnInfo
crtableLogoninfo.ConnectionInfo = connection
CrTable.ApplyLogOnInfo(crtableLogoninfo)
Next
rptDocs1.SetDatabaseLogon(connection.UserID, connection.Password, connection.ServerName, connection.DatabaseName)
rptDocs1.SetDataSource(SQL.SQLDS.Tables(0))
ReportByOrder.CrystalReportViewer1.ReportSource = rptDocs1
ReportByOrder.ShowDialog()
ReportByOrder.Dispose()
'ReportByOrder is the name of the report viewer form
End If