 |
|
เรียกข้อมูลมา อยากให้ รวมกล่อง รวมโปรดักส์ เเละเรียกตามวันที่ที่ต้องการ ผมเขียนเเล้วมัน error ครับ มี Code ช่วยผมด้วย |
|
 |
|
|
 |
 |
|
อยากให้เรียกตามวันที่ ที่ต้องการ รวมกล่อง รวมโปรดักส์ เเละ ไม่เอาโปรดักส์ที่มีตัวเลขนำหน้ามาครับ มัน error ครับ
Code ที่ผมเขียนครับ
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 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
ส่วนนี่ Error ที่มันฟ้องมาครับ

ต้องทำยังไงครับ
Tag : .NET, VB.NET
|
|
 |
 |
 |
 |
Date :
2011-08-08 09:27:52 |
By :
crazy-Ugly |
View :
1206 |
Reply :
17 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
คุณใช้ sum และระบุ column อื่นด้วย จะต้องใช้ GROUP BY keydate,proid,proname เข้าไปด้วยครับ
|
 |
 |
 |
 |
Date :
2011-08-08 09:51:34 |
By :
webmaster |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ผมลองเเบบนี้ครับ แต่ผมเอาวันที่ที่เลือกออก ก็ยัง Error อยู่ครับ

|
ประวัติการแก้ไข 2011-08-08 11:35:51 2011-08-08 11:37:16
 |
 |
 |
 |
Date :
2011-08-08 11:32:47 |
By :
crazy-Ugly |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ผมเขียน 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
ผลลัพของโค๊ดด้านบนครับ

แต่มันยังไม่รวมให้ครับ
|
ประวัติการแก้ไข 2011-08-08 11:45:33
 |
 |
 |
 |
Date :
2011-08-08 11:44:28 |
By :
crazy-Ugly |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอความช่วยเหลือด้วยครับ
|
 |
 |
 |
 |
Date :
2011-08-08 15:32:55 |
By :
crazy-Ugly |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ช่วยด้วยครับ
|
 |
 |
 |
 |
Date :
2011-08-08 17:25:34 |
By :
crazy-Ugly |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
มาขอความช่วยเหลือ ทำเมือคืนไม่ได้เลยครับ ช่วยด้วยครับ
|
 |
 |
 |
 |
Date :
2011-08-09 08:15:02 |
By :
crazy-Ugly |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ตัวที่ 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 "
ผมเอามาประยุกต์ใช้ไม่ได้เลยครับ
จะให้มัน รวมกล่อง รวมโปรดักส์ ไม่เอาโปรดักส์ที่มีรหัสเป็นตัวเลข และเรียกมาตามวันที่ที่ต้องการ
|
 |
 |
 |
 |
Date :
2011-08-09 08:26:06 |
By :
crazy-Ugly |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
จากกระทู้ที่ 3
ผมเรียก ตามวันที่ เเละไม่เอารหัสสินค้าที่มีตัวเลขมาใด้เเล้วครับ
แต่มันยังไม่รวม โปรดักส์ เเละรวมจำนวนกล่อง ของโปรดักส์ที่เหมือนกันครับ
ผมลัพพ์ที่ต้องการ
รหัสสินค้า ชื่อสินค้า จำนวนกล่อง
AA BSC SHOES 50
AC ELLE SHOES 55
AG NATURALIZER 40
|
 |
 |
 |
 |
Date :
2011-08-09 09:03:42 |
By :
crazy-Ugly |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code (C#)
select proid,proname,sum(box) as box from tblsum group by proid,proname ORDER BY proid"
ถ้าเขียนแบบนี้แล้วมันแสดงค่าไหมครับ?
|
 |
 |
 |
 |
Date :
2011-08-09 11:58:04 |
By :
Marcuz |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Items(2),
Items(3),
Items(4)
มันคืออะไรเหรอครับ?
ทำไมถึงเรียก 2,3,4
|
 |
 |
 |
 |
Date :
2011-08-09 12:48:20 |
By :
Marcuz |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ลำดับของ Column ครับ
|
 |
 |
 |
 |
Date :
2011-08-09 13:01:45 |
By :
webmaster |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ได้เเล้วครับ
ขอบคุณมากครับ ได้เเล้วครับ
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
|
 |
 |
 |
 |
Date :
2011-08-09 13:23:30 |
By :
crazy-Ugly |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
จบข่าว แก้กันตั้งสองวัน 
|
 |
 |
 |
 |
Date :
2011-08-09 13:32:13 |
By :
Marcuz |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|