 |
|
จะทำการ select ข้อมูล ซึ่งทีแรกจะ select รหัสที่มีการมารับบริการมากกว่า 1 ครั้งก่อน แล้วจึงจะเอารหัสที่ได้มาวนลูปเพื่อดึงรายละเอียดเข้ามาแสดงใน Datagridviwe เดิมทีใช้วิธีการ select ซ้อน Select แต่การคิวรี่ข้อมูลช้ามากก็เลยจะเปลี่ยนใหม่แต่ติดปัญหาที่ ต้องExecuteReader 2 ครั้ง ไม่ทราบว่ามีวิธีอื่นอีกหรือเปล่าที่จะจัดการกับปัญหานี้
ตัวอย่างโค้ดที่ทำแล้วมัน Error (มันฟ้องบอกว่า Reader ยังไม่เปิด)
Code (VB.NET)
Dim myDr As MySqlDataReader
Dim myDrEr As MySqlDataReader
Dim erRow As Integer = 0
If objConn.State = ConnectionState.Open Then
objConn.Close()
End If
Try
objConn.ConnectionString = strConn
objConn.Open()
Catch
MessageBox.Show("ไม่สารมารถติดต่อฐานข้อมูลได้กรุณาติดต่อผู้ดูแลระบบ")
End
End Try
strSQL = "select hn from opddata where dep1 = '021' AND left(icd10,1)<>'Z' and rdate between ('" & beginD & "') and ('" & endD & "') GROUP BY hn HAVING COUNT(hn) >1 order by hn "
myCom = New MySqlCommand(strSQL, objConn)
myDr = myCom.ExecuteReader
While myDr.Read
strSql1 = "select hn, rdate, name, icd10, icdName1 from opddata " & _
" where hn = '" & myDr("hn") & "' and dep1 = '021' AND left(icd10,1)<>'Z' and rdate between ('" & beginD & "') and ('" & endD & "')"
myCom = New MySqlCommand(strSql1, objConn)
myDrEr = myCom.ExecuteReader
While myDrEr.Read
DataGridView3.Rows.Add()
DataGridView3.Item(0, erRow).Value = myDrEr("hn")
DataGridView3.Item(1, erRow).Value = myDrEr("rdate")
DataGridView3.Item(2, erRow).Value = myDrEr("name")
DataGridView3.Item(3, erRow).Value = myDrEr("icd10")
DataGridView3.Item(4, erRow).Value = myDrEr("icdName1")
erRow += 1
End While
myDrEr.Close()
End While
myDr.Close()
***** รบกวนด้วยน่ะค่ะ *****
Tag : .NET, MySQL, VB.NET
|
|
 |
 |
 |
 |
Date :
2013-05-14 16:17:40 |
By :
MooT |
View :
1942 |
Reply :
2 |
|
 |
 |
 |
 |
|
|
|
 |