01.
If
cn.State = ConnectionState.Closed
Then
cn.Open()
02.
sql3 =
"select top 1 Idprintdocument from printdocument order by Idprintdocument DESC"
03.
cmd =
New
OleDbCommand(sql3, cn)
04.
adp =
New
OleDbDataAdapter(cmd)
05.
data =
New
DataSet
06.
adp.Fill(data,
"Idprintdocument"
)
07.
If
data.Tables(
"Idprintdocument"
).Rows.Count <> 0
Then
08.
tmpid =
CInt
(data.Tables(
"Idprintdocument"
).Rows(0).Item(
"Idprintdocument"
))
09.
tmpid = ((tmpid) + 1)
10.
Idsex3 = tmpid.ToString
11.
Label8.Text = tmpid.ToString
12.
Else
13.
tmpid = 1
14.
Idsex3 = tmpid.ToString
15.
Label8.Text = tmpid.ToString
16.
End
If
17.
18.
If
cn.State = ConnectionState.Closed
Then
cn.Open()
19.
cmd =
New
OleDbCommand(sql3, cn)
20.
data =
New
DataSet1
21.
adp =
New
OleDbDataAdapter(cmd)
22.
Dim
dd
As
Date
=
Date
.Now()
23.
For
i
As
Integer
= 0
To
DataGridView2.RowCount - 1
24.
sql3 = ......
25.
26.
27.
With
cmd
28.
.CommandType = CommandType.Text
29.
.CommandText = sql3
30.
.Connection = cn
31.
.ExecuteNonQuery()
32.
End
With
33.
34.
Next
35.
36.
frmOut.Show()
37.
38.
ฟอร์มที่สร้าง crystalreportview
39.
Option
Strict
On
40.
Imports
System
41.
Imports
System.Data
42.
Imports
System.Data.OleDb
43.
Imports
System.Globalization
44.
Imports
System.Threading
45.
Imports
CrystalDecisions.CrystalReports.Engine
46.
Imports
CrystalDecisions.ReportSource
47.
Imports
CrystalDecisions.
Shared
48.
Public
Class
frmOut
49.
Dim
conn
As
New
OleDbConnection
50.
Dim
Da
As
OleDbDataAdapter
51.
Dim
Cm
As
OleDbCommand
52.
Dim
StrSql
As
String
53.
Private
Sub
frmOut_Load(sender
As
Object
, e
As
EventArgs)
Handles
MyBase
.Load
54.
Try
55.
Cursor.Current = Cursors.WaitCursor
56.
With
conn
57.
If
.State = ConnectionState.Open
Then
.Close()
58.
.ConnectionString = ConStr
59.
.Open()
60.
End
With
61.
62.
StrSql &=
" Select *"
63.
StrSql &=
" From printdocument "
64.
StrSql &=
" where Idprintdocument = "
&
CInt
(Idsex3) &
""
65.
66.
67.
68.
Da =
New
OleDbDataAdapter(StrSql, conn)
69.
Dim
Ds
As
New
DataSet1
70.
Ds.Clear()
71.
Da.Fill(Ds,
"printdocument1"
)
72.
73.
If
Ds.Tables(
"printdocument1"
).Rows.Count <> 0
Then
74.
Dim
rpt
As
New
CrystalReportOut
75.
rpt.SetDataSource(Ds.Tables(
"printdocument1"
))
76.
CrystalReportViewer1.ReportSource = rpt
77.
CrystalReportViewer1.Refresh()
78.
79.
80.
Else
81.
MsgBox(
"ไม่พบข้อมูลที่ค้นหา"
, MsgBoxStyle.Critical,
"ผลการทำงาน"
)
82.
Me
.Close()
83.
End
If
84.
Cursor.Current = Cursors.
Default
85.
Catch
ex
As
Exception
86.
MsgBox(
"พบข้อผิดพลาดในการทำงาน"
& vbCrLf & ex.Message, MsgBoxStyle.Critical,
"ผลการทำงาน"
)
87.
End
Try
88.
89.
End
Sub
90.
91.
End
Class