 |
|
พอดี run project แล้วมัน error
โดยขึ้น code
there is already an open datareader associated with this command which must be closed first
ผมลองอ่านแล้ว มีพี่ๆบอกให้ปิด dataadpter ผมไม่รู้ว่าต้องปิดยังไง ผมอยากให้พี่ๆ ช่วยบอกวิธี หรือก วิธีแก้ error code ทีนะครับ
ขอบคุณครับ
Code (VB.NET)
Imports System.Data.SqlClient
Public Class FrmViewInven
Public tmp, Time As String
Dim adt As SqlDataAdapter
Dim dt As DataTable
Dim ds As DataSet
Private Sub FrmViewInven_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Try
With myConn
If .State = ConnectionState.Open Then .Close()
.ConnectionString = strconn
.Open()
End With
Connect()
myConn.Open()
liv()
Catch ex As Exception
MsgBox(ex.Message)
Finally
myConn.Close()
End Try
End Sub
Private Sub BtnView_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnView.Click
Try
With myConn
If .State = ConnectionState.Open Then .Close()
.ConnectionString = strconn
.Open()
End With
myConn.Open()
If livInvo.SelectedItems.Count = 0 Then
MessageBox.Show("กรุณาเลือกใบเบิกพัสดุที่ต้องการ !!!", "ผลการเลิกใบเบิกพัสดุ", MessageBoxButtons.OK, MessageBoxIcon.Warning)
Else
'****************************
'เป็นการเลือกที่ liv แล้วเปิดเอกสารที่ต้องการ
'****************************
Dim A As Form = New FrmAppWithDraw
A.Show()
' Show(FrmAppWithDraw)
End If
Catch ex As Exception
MsgBox(ex.Message, "Error2")
Finally
myConn.Close()
End Try
End Sub
Sub liv()
Try
sql = "SELECT WithDrawInvo.Withdraw_id, WithDrawInvo.DateWithDraw, WithDrawInvo.UserPK, WithDrawInvo.ActiveTF, " & _
"WithDrawInvo.TotalMoney, WithDrawInvo.ActiveBoss " & _
"FROM WithDrawInvo INNER JOIN " & _
" DbMember ON WithDrawInvo.UserPK = DbMember.UserPK " & _
"WHERE (WithDrawInvo.ActiveBoss = 0) AND (DbMember.Division_id = '" & DivisionID & "')"
' Dim adt As SqlDataAdapter = New SqlDataAdapter("select * from WithDrawInvo where Activeboss= 0 and division_id='" & DivisionID & "' ", myConn)
Dim adt As SqlDataAdapter = New SqlDataAdapter(sql, myConn)
Dim ds As DataSet = New DataSet
adt.Fill(ds, "View")
Dim dt As DataTable = New DataTable
dt = ds.Tables("View")
For i = 0 To dt.Rows.Count - 1 Step 1
Dim lvi = New ListViewItem(dt.Rows(i).Item(0).ToString) 'ID
'lbNo.Text = dt.Rows(i).Item(0).ToString
lvi.SubItems.Add(Format(CDate(dt.Rows(i).Item(1).ToString), "dd/MM/yyyy"))
lvi.SubItems.Add(dt.Rows(i).Item(2).ToString)
lvi.SubItems.Add(dt.Rows(i).Item(3).ToString)
lvi.SubItems.Add(dt.Rows(i).Item(4).ToString)
livInvo.Items.Add(lvi)
Next
livInvo.Sort()
Catch ex As Exception
MsgBox(ex.Message, "Error1")
Finally
myConn.Close()
End Try
End Sub
Private Sub livInvo_ItemSelectionChanged(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ListViewItemSelectionChangedEventArgs) Handles livInvo.ItemSelectionChanged
With myConn
If .State = ConnectionState.Open Then .Close()
.ConnectionString = strconn
.Open()
End With
adt = New SqlDataAdapter("select * from WithDrawInvo", myConn)
ds = New DataSet
adt.Fill(ds, "View")
dt = New DataTable
dt = ds.Tables("View")
For i = 0 To livInvo.SelectedItems.Count - 1 Step 1
'lbNo.Text = livInvo.SelectedItems.Item(i).SubItems(0).Text
tmp = livInvo.SelectedItems.Item(i).SubItems(0).Text
Time = livInvo.SelectedItems.Item(i).SubItems(1).Text
Name = livInvo.SelectedItems.Item(i).SubItems(2).Text
Next
End Sub
Private Sub livInvo_DoubleClick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles livInvo.DoubleClick
BtnView_Click(sender, e)
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
livInvo.Items.Clear()
FrmViewInven_Load(sender, e)
End Sub
End Class
Tag : .NET, VB.NET
|
|
 |
 |
 |
 |
Date :
2012-01-31 14:02:58 |
By :
moozap |
View :
1841 |
Reply :
2 |
|
 |
 |
 |
 |
|
|
|
 |