 |
|
Error:There is already an open DataReader associated with this Command which must be closed first. |
|
 |
|
|
 |
 |
|
dataadapter เป็น connection less ใยต้องไปเปิด connection ทิ้งไว้
ให้ไปปิดบัดเดี๋ยวนี้ ก่อนจะสั่ง fill
|
 |
 |
 |
 |
Date :
2010-11-09 08:21:31 |
By :
tungman |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
แก้ได้แล้วค่ะ ชอบคุณมากนะค่ะ
พี่ค่ะ ถ้า โปรแกรม มันไม่โชว์ ดา้ต้ากริด ค่ะ เพิ่มใหม่ ก็ ไม่ ไม่แสดงอ่ะ ค่ะ ทั้งที่ visible ก็เป้น true มีสิทธ์เป้นที่โปรแกรม มันไม่เอ๋อ หรือป่าวค่ะ
แล้ว ถ้า ต้องทำยังไง ค่ะ เพราะว่า โค้ดเครื่องอื่นหรือ หน้าบางหน้าที่เคยรันได้ก็มารันไม่ได้ค่ะ
|
 |
 |
 |
 |
Date :
2010-11-09 12:35:54 |
By :
jaoa |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
รบกวนหน่อยค่ะ ถ้าโค้ดแบบนี้ Error there is already an open datareader associated with this command which must be closed first ต้องแก้ไขตรงไหนค่ะ
Code (VB.NET)
Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
If txtMemberID.Text = "" Then
MessageBox.Show("กรุณาระบุรหัสบัตรผู้ยืม !!!", "ผลการตรวจสอบ", MessageBoxButtons.OK, MessageBoxIcon.Information)
txtMemberID.Focus()
Exit Sub
End If
If lsvEquList.Items.Count = 0 Then
MessageBox.Show("กรุณาป้อนรายการยืมอุปกรณ์ !!!", "ผลการตรวจสอบ", MessageBoxButtons.OK, MessageBoxIcon.Information)
txtEquID.Focus()
Exit Sub
End If
Dim sqlLend As String = ""
Dim comLend As SqlCommand = New SqlCommand
With Conn
If .State = ConnectionState.Open Then .Close()
.ConnectionString = strConn
.Open()
End With
Try
If MessageBox.Show("คุณต้องการบันทึกรายการยืมอุปกรณ์ ใช่หรือไม่?", "คำยืนยัน", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = DialogResult.Yes Then
AutoGenerateLendID()
sqlLend = "INSERT INTO Lend (LendID,MemberID,NetReceived,Return_StatusAll) "
sqlLend &= " VALUES('" & LastLendID & "',"
sqlLend &= "'" & txtMemberID.Text & "',"
sqlLend &= "0,'0')"
With comLend
.CommandType = CommandType.Text
.CommandText = sqlLend
.Connection = Conn
.ExecuteNonQuery()
End With
Dim i As Integer = 0
Dim tmpEquipmentID As String = ""
Dim sqlEquipment As String = ""
Dim tmpEquipmentInStock As Integer = 0
Dim tmpEquipmentInLend As Integer = 0
Dim tmpEquipmentNum As Integer = 0
Dim tmpDateNum As Integer = 0
Dim tmpAmount As Integer = 0
Dim tmpSum As Integer = 0
Dim tmpNet As Integer = 0
Dim tmpLendDate As Date
Dim tmpReturnDate As Date
tmpLendDate = Date.Now
For i = 0 To lsvEquList.Items.Count - 1
sqlLend = "INSERT INTO LendDetail(LendID,EquipmentID,Lend_Date,"
sqlLend &= " Return_Date,Lend_Num,AmountReceived,Return_Status)"
sqlLend &= " VALUES('" & LastLendID & "',"
tmpEquipmentID = lsvEquList.Items(i).SubItems(0).Text
tmpEquipmentNum = CInt(lsvEquList.Items(i).SubItems(2).Text)
tmpDateNum = CInt(lsvEquList.Items(i).SubItems(3).Text)
tmpAmount = CInt(lsvEquList.Items(i).SubItems(4).Text)
sqlLend &= "'" & tmpEquipmentID & "',"
sqlLend &= "'" & tmpLendDate & "',"
tmpReturnDate = tmpLendDate.AddDays(tmpDateNum)
sqlLend &= "'" & tmpReturnDate & "',"
sqlLend &= tmpEquipmentNum & ","
tmpSum = (tmpEquipmentNum * tmpDateNum * tmpAmount)
sqlLend &= tmpNet & ","
sqlLend &= "'0')"
With comLend
.CommandText = sqlLend
.ExecuteNonQuery()
End With
sqlEquipment = "SELECT EquipmentID,Equip_InStock,Equip_InLend FROM Equipment"
sqlEquipment &= " WHERE (EquipmentID='" & tmpEquipmentID & "')"
da.SelectCommand.CommandText = sqlEquipment
da.Fill(ds, "Equipment")
tmpEquipmentInStock = CInt(ds.Tables("Equipment").Rows(0).Item("Equip_InStock"))
tmpEquipmentInLend = CInt(ds.Tables("Equipment").Rows(0).Item("Equip_InLend"))
ds.Tables("Equipment").Clear()
sqlLend = "UPDATE Equipment"
sqlLend &= " SET Equip_InStock=" & tmpEquipmentInStock - tmpEquipmentNum & ","
sqlLend &= " Equip_InLend=" & tmpEquipmentInLend + tmpEquipmentNum
sqlLend &= " WHERE (EquipmentID='" & tmpEquipmentID & "')"
With comLend
.CommandText = sqlLend
.ExecuteNonQuery()
End With
Next
MessageBox.Show("บันทึกรายการยืมอุปกรณ์เรียบร้อยแล้ว !!!", "ผลการทำงาน", MessageBoxButtons.OK, MessageBoxIcon.Information)
If IsInstallPrinter() = True Then
If prDlg.ShowDialog = DialogResult.OK Then
prDoc.Print()
End If
Else
MessageBox.Show("กรุณาติดตั้งเครื่อง Printer ก่อนสั่งพิมพ์เอกสาร", "ผลการตรวจสอบ", MessageBoxButtons.OK, MessageBoxIcon.Information)
End If
ClearAllMemberData()
ClearAllEquipmentData()
lsvEquList.Items.Clear()
cboPosition.SelectedIndex = 0
txtMemberID.Enabled = True
txtMemberID.Focus()
End If
Catch ErrProcess As Exception
MessageBox.Show("ไม่สามารถบันทึกรายการยืมอุปกรณ์ได้ เนื่องจาก " & ErrProcess.Message, "ข้อผิดพลาด", MessageBoxButtons.OK, MessageBoxIcon.Warning)
Exit Sub
End Try
End Sub
|
 |
 |
 |
 |
Date :
2013-01-22 02:42:49 |
By :
แต้ว |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอโทษค่ะ Close ตัว DataReader อันแรกตรงไหนค่ะ รบกวนด้วยนะค่ะ
|
 |
 |
 |
 |
Date :
2013-01-22 23:16:03 |
By :
แต้ว |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
คุณคงจะต้อง Debug แล้วครับ เพราะรู้สึกจะมี Sub ย่อยหลายตัว 
|
 |
 |
 |
 |
Date :
2013-01-23 05:41:12 |
By :
mr.win |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ยังทำไม่ได้เลยค่ะ รบกวนแก้ไขให้ดูได้ไหมค่ะ
|
 |
 |
 |
 |
Date :
2013-01-30 22:46:49 |
By :
แตว |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|