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 ='" & tz.Text & "'"
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()
butre.Enabled = False
butsup.Enabled = True
butprint.Enabled = False
tsl1.Text = sum3().ToString("#,##0")
End Sub
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
Using con As New SqlConnection("data source=woody;initial catalog=transport;uid=sa;pwd=47222420322")
con.Open()
'ดึงข้อมูลมาเเสดงใน Datagrid แบบ Sum product และ box
'Dim sql As String = "select * from tblsum where zone ='" & tz.Text & "'"
Dim sql As String = "select proid,proname,sum(box) as box from tblsum where zone='N' group by proid,proname"
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()
butre.Enabled = False
butsup.Enabled = True
butprint.Enabled = False
tsl1.Text = sum3().ToString("#,##0")
End Sub
ผมทำแบบนี้ครับแต่ดันเอาไปใส่หลัง Group By ฟ้อง Error ตลอดครับ
Dim sql As String = "select proid,proname,sum(box) as box from tblsum group by proid,proname where zone='N'"