Private Sub Form2_Load
With mySQLConn
If .State = ConnectionState.Open Then Close()
.ConnectionString = Module1.conn
.Open()
End With
Dim sql As String
Dim da As New SqlDataAdapter
sql = "Select top 1 * From View_report ORDER BY id DESC"
cmd = New SqlCommand(sql, mySQLConn)
dr = cmd.ExecuteReader
dr.Read()
TextBox1.Text = dr.Item("emp_id").ToString
dr.Close()
Code (VB.NET)
Private Sub CrystalReportViewer1_Load
Dim rpt As New CrystalReport1
' ---- เพิ่มโค้ดส่วนนี้ สำหรับแต่ละตารางในรายงาน
Dim log As CrystalDecisions.Shared.TableLogOnInfo
log = rpt.Database.Tables("View_report").LogOnInfo ' ---- แก้ชื่อตารางด้วย
With log.ConnectionInfo
.UserID = "sa" ' ---- กำหนด User ID
.Password = "buddy716" ' ---- กำหนด Password
End With
rpt.Database.Tables("View_report").ApplyLogOnInfo(log) ' ---- ให้เอาข้อมูล LogOn ใหม่ไปใช้
rpt.SetParameterValue("Rid", TextBox1.Text)
rpt.RecordSelectionFormula = "{VIEW_report.emp_id} = {?Rid}"
CrystalReportViewer1.ReportSource = rpt