If cn.State = ConnectionState.Closed Then cn.Open()
sql3 = "select top 1 Idprintdocument from printdocument order by Idprintdocument DESC"
cmd = New OleDbCommand(sql3, cn)
adp = New OleDbDataAdapter(cmd)
data = New DataSet
adp.Fill(data, "Idprintdocument")
If data.Tables("Idprintdocument").Rows.Count <> 0 Then
tmpid = CInt(data.Tables("Idprintdocument").Rows(0).Item("Idprintdocument"))
tmpid = ((tmpid) + 1)
Idsex3 = tmpid.ToString
Label8.Text = tmpid.ToString
Else
tmpid = 1
Idsex3 = tmpid.ToString
Label8.Text = tmpid.ToString
End If
If cn.State = ConnectionState.Closed Then cn.Open()
cmd = New OleDbCommand(sql3, cn)
data = New DataSet1
adp = New OleDbDataAdapter(cmd)
Dim dd As Date = Date.Now()
For i As Integer = 0 To DataGridView2.RowCount - 1
sql3 = ......
' Cm SqlCommand
With cmd
.CommandType = CommandType.Text
.CommandText = sql3
.Connection = cn
.ExecuteNonQuery()
End With
' Idsex3 = tmpid.ToString
Next
frmOut.Show()
ฟอร์มที่สร้าง crystalreportview
Option Strict On
Imports System
Imports System.Data
Imports System.Data.OleDb
Imports System.Globalization
Imports System.Threading
Imports CrystalDecisions.CrystalReports.Engine
Imports CrystalDecisions.ReportSource
Imports CrystalDecisions.Shared
Public Class frmOut
Dim conn As New OleDbConnection
Dim Da As OleDbDataAdapter
Dim Cm As OleDbCommand
Dim StrSql As String
Private Sub frmOut_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Try
Cursor.Current = Cursors.WaitCursor
With conn
If .State = ConnectionState.Open Then .Close()
.ConnectionString = ConStr
.Open()
End With
StrSql &= " Select *"
StrSql &= " From printdocument "
StrSql &= " where Idprintdocument = " & CInt(Idsex3) & ""
'MsgBox(Idsex3)
Da = New OleDbDataAdapter(StrSql, conn)
Dim Ds As New DataSet1
Ds.Clear()
Da.Fill(Ds, "printdocument1")
'Dim Idsex1 As String = Idsex
If Ds.Tables("printdocument1").Rows.Count <> 0 Then
Dim rpt As New CrystalReportOut
rpt.SetDataSource(Ds.Tables("printdocument1"))
CrystalReportViewer1.ReportSource = rpt
CrystalReportViewer1.Refresh()
' CrystalReportViewer1.PrintReport()
' Close()
Else
MsgBox("ไม่พบข้อมูลที่ค้นหา", MsgBoxStyle.Critical, "ผลการทำงาน")
Me.Close()
End If
Cursor.Current = Cursors.Default
Catch ex As Exception
MsgBox("พบข้อผิดพลาดในการทำงาน" & vbCrLf & ex.Message, MsgBoxStyle.Critical, "ผลการทำงาน")
End Try
End Sub
End Class