com()
For i = 0 To GridView2.Rows.Count - 1
strSql3 = "select Drug.D_Name, sum(stock_qty)as stock1 from Stock,Drug where stock.CT_id=" & GridView2.Rows(i).Cells(3).Text & " and stock.D_id=Drug.D_id and stock.D_id=" & GridView2.Rows(i).Cells(1).Text & " AND stock.stock_status='Y' GROUP BY Drug.D_Name"
With cmd3
.CommandText = strSql3
.CommandType = CommandType.Text
.Connection = conn
crm = .ExecuteReader()
End With
If crm.Read = True Then
If CInt(crm.Item("stock1")) < CInt(GridView2.Rows(i).Cells(2).Text) Then
MsgBox("ไม่สามารถสั่งยา " & crm.Item("D_Name") & " เนื่องจากยาไม่เพียงพอ")
Exit Sub
End If
End If
crm.Close()
Next
For i = 0 To GridView2.Rows.Count - 1
strSql3 = "select stock_id, stock_qty from Stock where stock.CT_id=" & GridView2.Rows(i).Cells(3).Text & " And Stock.D_id=" & GridView2.Rows(i).Cells(1).Text & " AND stock.stock_status='Y' order by date1 ASC"
With cmd3
.CommandText = strSql3
.CommandType = CommandType.Text
.Connection = conn
crm = .ExecuteReader()