01.
Dim
conStr
As
String
=
"Data Source=.\SQLEXPRESS;AttachDbFilename='C:\Visual Studio 2008\Projects\PROJECT MORYA.mdf';Integrated Security=True;Connect Timeout=30;User Instance=True"
02.
Dim
conn
As
New
SqlConnection(conStr)
03.
conn.Open()
04.
Dim
sql
As
String
=
"Select date,pharmacist_name,supplier_name,product_serialno,product_name,quantity,causes From returndetail"
05.
Dim
cmd
As
New
SqlCommand(sql, conn)
06.
Dim
adapter
As
New
SqlDataAdapter(cmd)
07.
Dim
data
As
New
DataSet()
08.
09.
adapter.Fill(data,
"returndetail"
)
10.
DataGridView1.DataSource = data.Tables(
"returndetail"
)
11.
12.
DataGridView1.Columns(
"date"
).HeaderText =
"วันที่คืนสินค้า"
13.
DataGridView1.Columns(
"pharmacist_name"
).HeaderText =
"ชื่อเภสัชกร"
14.
DataGridView1.Columns(
"supplier_name"
).HeaderText =
"ชื่อตัวแทนจำหน่าย"
15.
DataGridView1.Columns(
"product_serialno"
).HeaderText =
"รหัสสินค้า"
16.
DataGridView1.Columns(
"product_name"
).HeaderText =
"ชื่อสินค้า"
17.
DataGridView1.Columns(
"quantity"
).HeaderText =
"จำนวน"
18.
DataGridView1.Columns(
"causes"
).HeaderText =
"สาเหตุที่คืน"
19.
20.
21.
22.
sb.Remove(0, sb.Length)
23.
sb.Append(
"Select date,pharmacist_name,supplier_name,product_serialno,product_name,quantity,causes From returndetail"
)
24.
sb.Append(
" Where (date Between '"
& DateTimePicker1.Value.Month.ToString &
" / "
& DateTimePicker1.Value.Day.ToString &
" / "
& DateTimePicker1.Value.Year.ToString &
"' And '"
& DateTimePicker2.Value.Month.ToString &
" / "
& DateTimePicker2.Value.Day.ToString &
" / "
& DateTimePicker2.Value.Year.ToString &
"')"
)
25.
strSql = sb.ToString()
26.
cm =
New
SqlCommand()
27.
With
cm
28.
.CommandText = strSql
29.
.Connection = cn
30.
dr = .ExecuteReader()
31.
32.
End
With
33.
If
dr.HasRows
Then
34.
Dim
dtSql
As
DataTable
35.
dtSql =
New
DataTable()
36.
dtSql.Load(dr)
37.
With
DataGridView1
38.
.DataSource = dtSql
39.
End
With
40.
Else
41.
MessageBox.Show(
"ช่วงเวลาที่คุณระบุ ไม่มีรายการคืน !!!"
,
"ผลการตรวจสอบ"
, MessageBoxButtons.OK, MessageBoxIcon.Information)
42.
DateTimePicker1.Focus()
43.
End
If
44.
dr.Close()