ฟอร์ม แสดงรายงาน
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Mconn.Connnect()
sb.Remove(0, sb.Length)
sb.Append("SELECT tbl_tcustomer.`Type_name`,tbl_customer.`Id_customer`,tbl_customer.`Customer_name`,tbl_customer.`Cus_address`,tbl_customer.`Cus_phone`,tbl_customer.`Cus_email`")
sb.Append(" FROM tbl_tcustomer INNER JOIN tbl_customer ON tbl_tcustomer.`id_tcustomer` = tbl_customer.`Id_tcustomer`")
sql = sb.ToString
Cmd.CommandText = sql
Cmd.Connection = Conn
dtAdapter.SelectCommand = Cmd
dtAdapter.Fill(ds)
strreprotname = "Report1"
Dim strreportpath As String = Application.StartupPath & "\" & strreprotname & ".rpt"
If Not IO.File.Exists(strreportpath) Then
Throw (New Exception("unable to locate report file: " & vbCrLf & strreportpath))
End If
Dim rptdocument As New CrystalDecisions.CrystalReports.Engine.ReportDocument
rptdocument.Load(strreportpath)
rptdocument.SetDataSource(ds.Tables(0))
CrystalReportViewer1.ShowRefreshButton = False
CrystalReportViewer1.ShowCloseButton = False
CrystalReportViewer1.ShowGroupTreeButton = False
CrystalReportViewer1.ReportSource = rptdocument
End Sub
End Class
ฟอร์ม ติดต่อฐานข้อมูล
Code (VB.NET)
Imports System.Text
Imports System.Data
Imports System.Data.OleDb
Module Mconn
Public sql As String
Public Conn As New OleDbConnection
Public Cmd As New OleDbCommand
Public ds As New DataSet
Public dtAdapter As New OleDbDataAdapter
Public strreprotname As String
Public strConn As String
Public sb As New StringBuilder()
Sub Connnect()
strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source= " & Application.StartupPath & "\db_wshop.mdb"
Conn = New OleDbConnection()
With Conn
If .State = ConnectionState.Open Then .Close()
.ConnectionString = strConn
.Open()
End With
End Sub
End Module
รบกวนดูให้หน่ยนะคับ
ปกติก ถ้า select ตารางเดียวจะแสดงข้อมูลได้ ไม่ติดรหัสผ่าน แต่พอ join 2 ตาราง ออกรายงานไม่ได้ติดรหัสผ่าน