แต่ ผมทำแล้วมันแสดงค่า name สุดท้ายชื่อเดียวกับ อยากได้ทุก name คับ ไม่รู้ทำไง หรือ ผิดตรงไหน ช่วยแนะนำทีคับบบ ขอบคุณคับบบ
นี้Code ผม คับ ช่วยดูทีคับบบ Code (VB.NET)
Dim StrConn1 As String
Dim Sql As String
StrConn1 = WebConfigurationManager.ConnectionStrings("conn").ConnectionString
Dim Conn1 As New SqlConnection(StrConn1)
Conn1.Open()
Dim month_old As Integer = Month(Date.Now) - 1
Sql = "SELECT name_drug, sum(quantity_sale) as total_sale FROM drug_sale WHERE month(date_sale) = '" & month_old & "' GROUP BY name_drug "
Dim sqlCom As New SqlCommand(Sql, Conn1)
Dim dr As SqlDataReader = sqlCom.ExecuteReader
While dr.Read()
Dim name_drug_old = dr.Item("name_drug")
Dim total_sale_old = dr.Item("total_sale")
bbb.Text = month_old
Dim strConn2 As String
Dim sqluername2 As String
strConn2 = WebConfigurationManager.ConnectionStrings("conn").ConnectionString
Dim Conn2 As New SqlConnection(strConn2)
Conn2.Open()
sqluername2 = "SELECT name_drug, mode, sum(quantity) As total_quantity FROM drug INNER JOIN mode ON drug.id_mode = mode.id_mode WHERE name_drug = '" & name_drug_old & "' GROUP BY name_drug, mode HAVING(sum(quantity) <= '" & total_sale_old & "') order by total_quantity "
Dim da2 As New SqlDataAdapter(sqluername2, Conn2)
Dim ds2 As New DataSet
da2.Fill(ds2, "drug")
GridView2.DataSource = ds2.Tables("drug")
GridView2.DataBind()
End While
dr.Close()
Conn1.Close()