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"
Dim conn As New SqlConnection(conStr)
conn.Open()
Dim sql As String = "Select date,pharmacist_name,supplier_name,product_serialno,product_name,quantity,causes From returndetail"
Dim cmd As New SqlCommand(sql, conn)
Dim adapter As New SqlDataAdapter(cmd)
Dim data As New DataSet()
adapter.Fill(data, "returndetail")
DataGridView1.DataSource = data.Tables("returndetail")
DataGridView1.Columns("date").HeaderText = "วันที่คืนสินค้า"
DataGridView1.Columns("pharmacist_name").HeaderText = "ชื่อเภสัชกร"
DataGridView1.Columns("supplier_name").HeaderText = "ชื่อตัวแทนจำหน่าย"
DataGridView1.Columns("product_serialno").HeaderText = "รหัสสินค้า"
DataGridView1.Columns("product_name").HeaderText = "ชื่อสินค้า"
DataGridView1.Columns("quantity").HeaderText = "จำนวน"
DataGridView1.Columns("causes").HeaderText = "สาเหตุที่คืน"
sb.Remove(0, sb.Length) '' คำสั่ง Query ข้อมูล
sb.Append("Select date,pharmacist_name,supplier_name,product_serialno,product_name,quantity,causes From returndetail")
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 & "')")
strSql = sb.ToString() '' เก็บใน String
cm = New SqlCommand()
With cm
.CommandText = strSql
.Connection = cn
dr = .ExecuteReader()
End With
If dr.HasRows Then ''check dr
Dim dtSql As DataTable
dtSql = New DataTable()
dtSql.Load(dr)
With DataGridView1
.DataSource = dtSql
End With
Else
MessageBox.Show("ช่วงเวลาที่คุณระบุ ไม่มีรายการคืน !!!", "ผลการตรวจสอบ", MessageBoxButtons.OK, MessageBoxIcon.Information)
DateTimePicker1.Focus()
End If
dr.Close()