codice:
'Salva nel DB i Dati anagrafici del Professionista TblAnagraficaPROF - FrmProf:
Public Sub SalvaDBAnagPr()
Dim Ogg1 As New ADODB.Command
Dim Cns1 As New ADODB.Connection
Dim RSTctr As New ADODB.Recordset
' Il file deve essere salvato nel DB:
btConf = 0
'Esegue la connessione con il DataBase TblAnagraficaPROF:
With Cns1
.ConnectionString = DataConnessione
.CursorLocation = adUseClient 'tipo di cursore
.Mode = adModeShareDenyNone 'nessuna limitazione
.CommandTimeout = 15
.Open
End With
' Controlla che il professionista ed il progetto NON sia inserito già nel BD:
RSTctr.Source = "SELECT Nome, Cognome, NomeFile FROM TblAnagraficaPROF WHERE Nome='" & FrmAnagProf.TxtPr1.Text & "' And Cognome='" & FrmAnagProf.TxtPr2.Text & "' And NomeFile= '" & NomeNF & "'"
RSTctr.Open , Cns1
' Il Professionista è presente nel DB, esce dalla routine:
If RSTctr.EOF = False And RSTctr.BOF = False Then
MsgBox "Il professionista: " & FrmAnagProf.TxtPr1.Text & " " & FrmAnagProf.TxtPr2.Text & " che ha redatto il computo metrico " & NomeNF & Chr(13) _
& "è già registrato nel database.", vbInformation + vbOKOnly, "AA - Determinazione ....."
' Conferma il salvataggio nel DB:
btConf = 1
' Indica che il file è stato salvato:
boolVerifica2 = True
End If
If RSTctr.EOF = True And RSTctr.BOF = True Then
' Il Professionista che ha redatto il progetto Non è presente nel DB, viene inserito:
Ogg1.ActiveConnection = Cns1
Ogg1.CommandType = adCmdText
Ogg1.CommandText = "insert into TblAnagraficaPROF(Titolo, Nome, Cognome, PartitaIVA, Ordine, Matricola, TipoVia, Via, NCivico, Cap, Citta, Provincia, Telefono, Cellulare, Fax, Email, NomeFile)" _
& "values ('" & Replace(FrmAnagProf.CmbPr1.Text, "'", "''") & "', '" & Replace(FrmAnagProf.TxtPr1.Text, "'", "''") & "', '" & Replace(FrmAnagProf.TxtPr2.Text, "'", "''") _
& "', '" & Replace(FrmAnagProf.TxtPr3.Text, "'", "''") & "', '" & Replace(FrmAnagProf.CmbPr4.Text, "'", "''") & "' ,'" & Replace(FrmAnagProf.TxtPr12.Text, "'", "''") _
& "', '" & Replace(FrmAnagProf.CmbPr2.Text, "'", "''") & "', '" & Replace(FrmAnagProf.TxtPr4.Text, "'", "''") & "' ,'" & Replace(FrmAnagProf.TxtPr5.Text, "'", "''") _
& "', '" & Replace(FrmAnagProf.TxtPr6.Text, "'", "''") & "', '" & Replace(FrmAnagProf.TxtPr7.Text, "'", "''") & "' ,'" & Replace(FrmAnagProf.CmbPr3.Text, "'", "''") _
& "', '" & Replace(FrmAnagProf.TxtPr8.Text, "'", "''") & "', '" & Replace(FrmAnagProf.TxtPr9.Text, "'", "''") & "', '" & Replace(FrmAnagProf.TxtPr10.Text, "'", "''") _
& "', '" & Replace(FrmAnagProf.TxtPr11.Text, "'", "''") & "', '" & Replace(FrmAnagProf.TxtNomeF.Text, "'", "''") & "');"
Ogg1.Execute
' Conferma il salvataggio nel DB:
btConf = 1
' Indica che il file è stato salvato:
boolVerifica2 = True
End If
' Chiude la connessione:
Cns1.Close
Set Cns1 = Nothing
'Chiude e cancella il recordSet:
Set RSTctr = Nothing
RSTctr.Close
End Sub