Private Sub butre_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles butre.Click
If MessageBox.Show("คุณต้องการเรียกข้อมูลใช่หรือไม่?", "Database", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.Yes Then
'****การดึงข้อมูลมาโชว์ใน DataGrid****'
Using con As New SqlConnection("data source=woody;initial catalog=transport;uid=sa;pwd=47222420322")
con.Open()
Dim sql As String = "select keydate,proid,proname,sum(box) as box from tblsum where keydate ='" & dtp.Value.ToString("MM/dd/yyyy") & "' and zone ='" & txt7.Text & "'and proid not like '%[0-9]%' order by proid "
Dim cmd As SqlCommand = New SqlCommand(sql, con)
Dim dr As SqlDataReader = cmd.ExecuteReader
Dim dt = New DataTable
If dr.HasRows Then
Dim r As Integer = 0
While dr.Read
With DataGridView1
r = .RowCount - 1
.Rows.Add()
.Rows(r).Cells(0).Value = dr.Item(2)
.Rows(r).Cells(1).Value = dr.Item(3)
.Rows(r).Cells(2).Value = dr.Item(4)
End With
End While
End If
End Using
End If
DataGridView1.Focus()
DataGridView1.Focus()
butsup.Enabled = True
butprint.Enabled = False
tsl1.Text = sum3().ToString("#,##0")
End Sub
ผมเขียน Select * from มันเรียกมาได้ครับ แต่ยังไม่รวม กลุ่มเเละรวมกล่อง
Code (VB.NET)
Private Sub butre_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles butre.Click
If MessageBox.Show("คุณต้องการเรียกข้อมูลใช่หรือไม่?", "Database", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.Yes Then
'****การดึงข้อมูลมาโชว์ใน DataGrid****'
Using con As New SqlConnection("data source=woody;initial catalog=transport;uid=sa;pwd=47222420322")
con.Open()
Dim sql As String = "select * from tblsum where keydate ='" & dtp.Value.ToString("MM/dd/yyyy") & "' and zone ='" & txt7.Text & "'and proid not like '%[0-9]%' order by proid "
Dim cmd As SqlCommand = New SqlCommand(sql, con)
Dim dr As SqlDataReader = cmd.ExecuteReader
Dim dt = New DataTable
If dr.HasRows Then
Dim r As Integer = 0
While dr.Read
With DataGridView1
r = .RowCount - 1
.Rows.Add()
.Rows(r).Cells(0).Value = dr.Item(2)
.Rows(r).Cells(1).Value = dr.Item(3)
.Rows(r).Cells(2).Value = dr.Item(4)
End With
End While
End If
End Using
End If
DataGridView1.Focus()
DataGridView1.Focus()
butsup.Enabled = True
butprint.Enabled = False
tsl1.Text = sum3().ToString("#,##0")
End Sub
ตัวที่ 1
Dim sql As String = "select proid,proname,sum(box) as box from tblsum where zone='N' group by proid,proname ORDER BY proid"
ตัวที่ 2
Dim sql As String = "select * from tblsum where keydate ='" & dtp.Value.ToString("MM/dd/yyyy") & "' and zone ='" & txt7.Text & "'and proid not like '%[0-9]%' order by proid "
Private Sub butre_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles butre.Click
If MessageBox.Show("คุณต้องการเรียกข้อมูลใช่หรือไม่?", "Database", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.Yes Then
'****การดึงข้อมูลมาโชว์ใน DataGrid****'
Using con As New SqlConnection("data source=woody;initial catalog=transport;uid=sa;pwd=47222420322")
con.Open()
Dim sql As String = "select proid,proname,sum(box) as box from tblsum where keydate ='" & dtp.Value.ToString("MM/dd/yyyy") & "' and zone ='" & txt7.Text & "'and proid not like '%[0-9]%' Group by proid,proname order by proid "
Dim cmd As SqlCommand = New SqlCommand(Sql, con)
Dim dr As SqlDataReader = cmd.ExecuteReader
Dim dt = New DataTable
If dr.HasRows Then
Dim r As Integer = 0
While dr.Read
With DataGridView1
r = .RowCount - 1
.Rows.Add()
.Rows(r).Cells(0).Value = dr.Item(0)
.Rows(r).Cells(1).Value = dr.Item(1)
.Rows(r).Cells(2).Value = dr.Item(2)
End With
End While
End If
End Using
End If
DataGridView1.Focus()
DataGridView1.Focus()
butsup.Enabled = True
butprint.Enabled = False
tsl1.Text = sum3().ToString("#,##0")
End Sub