DataReaderAperto

martedì 11 novembre 2008 - 12.58

ario Profilo | Junior Member

Non capisco x nel codice seguente mi da sempre l' errore
Al comando è già associato un DataReader aperto, che deve essere chiuso.

Private Sub Salva()
If txtNCommessa.Text.Trim = "" Then
Exit Sub
End If

Dim ArrayBarcode(2) As String
Dim INuovaCommessa As Integer = 0
Dim IRottamati As Integer = 0
Dim AIRiga As Integer = 0
Dim szBarcode As String = ""


If Conn.State = ConnectionState.Closed Then
Conn.Open()
End If

Dim Tx As OdbcTransaction
Tx = Conn.BeginTransaction
Dim cmd As OdbcCommand = Conn.CreateCommand


Try
cmd.Transaction = Tx

'APERTA = 0
'CHIUSA = 1
''''''''''''''''''''''''''''''''''
'Ricerca Ncommessa,cesta nela tabella consuntivi_lavorazioni
ArrayBarcode = Split(txtNCommessa.Text, "-")
mySelectQuery = "select * from consuntivi_produzione where ncommessa='" & ArrayBarcode(0) & "' and reparto = " & ArrayBarcode(1) & " and aperta=0"
cmd.CommandText = mySelectQuery
Dim myReader As OdbcDataReader
myReader = cmd.ExecuteReader()
If Not myReader.HasRows Then
MsgBox("ATTENZIONE!! Nessuna lavorazione aperta con la commessa selezionata", MsgBoxStyle.Critical)
txtNCommessa.Focus()
Exit Sub
End If
myReader.Close()

''''''''''''''''''''''''''''''
'Chiudo la lavorazione aperta
mySelectQuery = "update consuntivi_produzione set "
mySelectQuery = mySelectQuery & "dataora_fine='" & Replace(Format(Now, "yyyyMMdd hh:mm:ss"), ".", ":") & "'"
mySelectQuery = mySelectQuery & ",dipendente = " & txtOperatore.Text
mySelectQuery = mySelectQuery & ",pezzi_lavorati =" & txtPezzi.Text
mySelectQuery = mySelectQuery & ",pezzi_scartati = " & lblPezziScartati.Text
mySelectQuery = mySelectQuery & ",aperta = 1"
mySelectQuery = mySelectQuery & " where ncommessa = '" & ArrayBarcode(0) & "' and reparto = " & ArrayBarcode(1) & " and cesta = " & txtCesta.Text
cmd.CommandText = mySelectQuery
cmd.ExecuteNonQuery()


'''''''''''''''''''''''''''''''''
'registro le motivazioni degli scarti se ci sono
If UBound(ArrayMotivazione) > 0 Then
Dim szNCommessa(2) As String
'Dim iRiga As Integer = 0
iRiga = 0
For iRiga = 1 To UBound(ArrayMotivazione)
If ArrayMotivazione(iRiga, iRiga) Is Nothing Then
Exit For
End If
ArrayBarcode = Split(ArrayMotivazione(iRiga, iRiga), ",")
mySelectQuery = "insert into scarti (ncommessa,reparto,cesta,pezzi_scartati,motivazione) values ( "
szNCommessa = Split(txtNCommessa.Text, "-")
mySelectQuery = mySelectQuery & "'" & szNCommessa(0) & "'"
mySelectQuery = mySelectQuery & "," & lblIdFase.Text
mySelectQuery = mySelectQuery & "," & txtCesta.Text
mySelectQuery = mySelectQuery & "," & Replace(ArrayBarcode(0), "'", "")
mySelectQuery = mySelectQuery & ",'" & Replace(ArrayBarcode(1), "'", "") & "'"
mySelectQuery = mySelectQuery & ")"
If ArrayBarcode(1) = "'Rottamati'" Then
IRottamati = IRottamati + Val(Replace(ArrayBarcode(0), "'", ""))
INuovaCommessa = 1
End If
cmd.CommandText = mySelectQuery
cmd.ExecuteNonQuery()
Next iRiga
End If


If IRottamati = 0 Then
GoTo PROSEGUI
End If

''''''''''''''''''''''''
'solo per pezzi scartati perchè rottamati
'Ristampo i fogli di lavorazione con la commessa +"X"
'Creo commessa NCOMMESSA+X di n.pezzi= pezzi scartati

ArrayBarcode = Split(txtNCommessa.Text, "-")
mySelectQuery = "select * from commesse where ncommessa = '" & ArrayBarcode(0) & "'"
cmd.CommandText = mySelectQuery
myReader = cmd.ExecuteReader()
If myReader.HasRows Then
While myReader.Read
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'Creazione record in tabella Commesse
mySelectQuery = "insert into commesse (ncommessa,data,articolo,descrizione,quantita,num_lancio,data_lancio,pezzi_x_conf)"
mySelectQuery = mySelectQuery & " values ("
mySelectQuery = mySelectQuery & "'" & txtNCommessa.Text.Trim + "X" & "'"
mySelectQuery = mySelectQuery & ",'" & Format(Now, "yyyyMMdd") & "'"
mySelectQuery = mySelectQuery & ",'" & myReader("articolo") & "'"
mySelectQuery = mySelectQuery & ",'" & myReader("descrizione") & "'"
mySelectQuery = mySelectQuery & "," & Replace(IRottamati, ",", ".")
mySelectQuery = mySelectQuery & "," & myReader("num_lancio")
mySelectQuery = mySelectQuery & ",'" & Format(myReader("data_lancio"), "yyyyMMdd") & "'"
mySelectQuery = mySelectQuery & "," & myReader("pezzi_x_conf")
mySelectQuery = mySelectQuery & ")"

cmd.CommandText = mySelectQuery
cmd.ExecuteNonQuery()
End While
End If
myReader.Close()

''''''''''''''''''''''''''''''''''''''''''''
'Recupero fasi di lavorazione
'''''''''''''''''''''''''''''''''''''''''''''''''
mySelectQuery = "select commesse_lavorazioni.*,fasi.descrizione from commesse_lavorazioni,fasi where ncommessa = '" & ArrayBarcode(0) & "' and commesse_lavorazioni.id_fase = fasi.id_fase"
cmd.CommandText = mySelectQuery
myReader = cmd.ExecuteReader()
AIRiga = 0
If myReader.HasRows Then
While myReader.Read
AIRiga = AIRiga + 1
mySelectQuery = "insert into commesse_lavorazioni (ncommessa,ordine,id_fase) values "
mySelectQuery = mySelectQuery & "("
mySelectQuery = mySelectQuery & "'" & myReader("ncommessa") + "X'"
mySelectQuery = mySelectQuery & "," & myReader("ordine")
mySelectQuery = mySelectQuery & "," & myReader("id_fase")
mySelectQuery = mySelectQuery & ")"
Array_Fasi(AIRiga) = myReader("ID_FASE")
Array_Descrizioni(AIRiga) = myReader("DESCRIZIONE")

cmd.CommandText = mySelectQuery
cmd.ExecuteNonQuery()
End While
End If
myReader.Close()


'''''''''''''''''''''''
'LANCIO LA STAMPA
For AIRiga = 1 To UBound(Array_Fasi)
If Array_Fasi(AIRiga) = 0 Then
Exit For
End If
iReports = AIRiga
Select Case AIRiga
Case Is = 1
'frmReports.Show()
'axCRY.ReportFileName = Application.StartupPath & "\Lavorazione.rpt"
frmArticoloQuantita.AXCRY.ReportFileName = Application.StartupPath & "\Lavorazione.rpt"
Case Is = 2
'frmReports1.Show()
frmArticoloQuantita.AXCRY.ReportFileName = Application.StartupPath & "\Lavorazione1.rpt"
Case Is = 3
'frmReports2.Show()
frmArticoloQuantita.AXCRY.ReportFileName = Application.StartupPath & "\Lavorazione2.rpt"
Case Is = 4
'frmReports3.Show()
frmArticoloQuantita.AXCRY.ReportFileName = Application.StartupPath & "\Lavorazione3.rpt"
Case Is = 5
'frmReports4.Show()
frmArticoloQuantita.AXCRY.ReportFileName = Application.StartupPath & "\Lavorazione4.rpt"
Case Is = 6
'frmReports5.Show()
frmArticoloQuantita.AXCRY.ReportFileName = Application.StartupPath & "\Lavorazione5.rpt"
End Select

ArrayBarcode = Split(txtNCommessa.Text, "-")
szBarcode = Calcolo_Barcode(ArrayBarcode(0) + "-" + CStr(Array_Fasi(iReports)))

frmArticoloQuantita.AXCRY.Connect = "UID=" & szUserId & ";PWD=" & szPassword
frmArticoloQuantita.AXCRY.ReportFileName = "c:\lavorazione.rpt"
frmArticoloQuantita.AXCRY.SelectionFormula = "{LANCI_PRODUZIONE.ncommessa}='" & ArrayBarcode(0) & "'"
frmArticoloQuantita.AXCRY.set_ParameterFields(0, "Reparto;" & Array_Fasi(iReports) & ";True")
frmArticoloQuantita.AXCRY.set_ParameterFields(1, "Descrizione_Fase;" & Array_Descrizioni(iReports) & ";True")
frmArticoloQuantita.AXCRY.set_ParameterFields(2, "Barcode;" & szBarcode & ";True")

frmArticoloQuantita.AXCRY.Destination = Crystal.DestinationConstants.crptToWindow
frmArticoloQuantita.AXCRY.Action = 1

Next
''''''''''''''''''''''


PROSEGUI:


mySelectQuery = ""

Tx.Commit()

txtNCommessa.Text = ""
txtCesta.Text = ""
txtPezzi.Text = ""
txtNCommessa.Focus()

Catch ex As Exception
MsgBox(ex.Message)
Tx.Rollback()
Finally
If Conn.State = ConnectionState.Open Then
Conn.Close()
End If
Tx = Nothing
cmd = Nothing
Me.Close()
End Try
End Sub

Alex1972 Profilo | Newbie

il Dr lo chiudi dopo l'Exit Sub...quindi il Dr rimane aperto....

Alex
Partecipa anche tu! Registrati!
Hai bisogno di aiuto ?
Perchè non ti registri subito?

Dopo esserti registrato potrai chiedere
aiuto sul nostro Forum oppure aiutare gli altri

Consulta le Stanze disponibili.

Registrati ora !
Copyright © dotNetHell.it 2002-2024
Running on Windows Server 2008 R2 Standard, SQL Server 2012 & ASP.NET 3.5