Visualizzazione dei risultati da 1 a 7 su 7
  1. #1
    Utente di HTML.it
    Registrato dal
    Apr 2002
    Messaggi
    271

    Consiglio codice corretto (VB)

    Vorrei sapere se questo codice che ho inserito è corretto e cioè
    dovrebbe fare questo:io nel mio form ho: un MaskEditBox(codice fiscale)ed una textbox (nome)
    1)inserisco codice fiscale quando perde il focus
    mi va a fare un controllo nel database se c'è già automaticamente
    mi mette nella txtnome il nome corrispondente a quel codice fiscale (ho tabella Anagrafica con 2 campi : nome e codicefiscale)
    se non c'è mi attiva il pulsante invia che va a controllare se sono stati inseriti nome e codice fiscale e se sono
    inseriti me li mette nel database
    E' CORRETTO IMPOSTARE IL TUTTO COSI'





    Private Function controllacodice(ByVal codf As String, ByRef dbConn As ADODB.Connection) As Boolean
    Dim dbRec As New ADODB.Recordset
    Dim strSQL As String

    strSQL = "SELECT * FROM Anagrafica WHERE codicefiscale = '" & codf & "'"
    DoEvents
    Set dbRec = dbConn.Execute(strSQL)
    controllacodice = Not dbRec.EOF
    Set dbRec = Nothing
    End Function


    ------------------------------------------------

    Private Sub MaskCodF_LostFocus()


    g_strConnection = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" _
    & App.Path & "\db1.mdb; Persist Security Info=False"

    Dim dbConn As New ADODB.Connection
    Dim strConnectionString As String
    Dim strSQL As String

    Dim iNome, iCod As String
    iNome = txtNome
    iCod = MaskCodf


    dbConn.ConnectionString = g_strConnectionString
    dbConn.Open

    Dim bRes As Boolean
    bRes = controllacodice(iCod, dbConn)
    If bRes = True Then
    txtNome.text= dbRec ("nome")
    dbConn.Close
    Set dbConn = Nothing
    Else
    cmdInvia.Enabled=True //attivo il pulsante di default l'ho impostato a false
    dbConn.Close
    Set dbConn = Nothing
    End If

    End Sub

    -------------------------------------
    Private Sub cmdInvia_Click()
    Dim iNome, iCod As String
    iNome = txtNome
    iCod = MaskCodf

    If txtNome = "" Or MaskCodf = "" Then
    MsgBox "Inserisci i campi obblibatori * mancanti", vbInformation
    Exit Sub
    End If

    dbConn.ConnectionString = g_strConnectionString
    dbConn.Open


    strSQL = "INSERT INTO Anagrafica (nome,codicefiscale) VALUES ' " & iNome & " ',' " & iCod & " ' "
    dbConn.Close
    Set dbConn = Nothing

    End If
    End Sub

    ------------------------------------------------------------

  2. #2
    Utente bannato
    Registrato dal
    Mar 2002
    Messaggi
    1,811

    beh ci ho dato un'occhiata leggera

    comunque mi sembra a posto..
    piuttosto dimmi quale è la tua difficoltà?
    ovvio che non avresti scritto al forum se andasse tutto liscio!

    http://amodio.too.it

  3. #3
    Utente di HTML.it
    Registrato dal
    Apr 2002
    Messaggi
    271
    Mi dà errore in due punti


    1)bRes = controllacodice(iCod, dbConn) Errore: ByRef dbConn

    2) txtNome.text= dbRec ("nome") Mi dice che non trova corrispondente,
    in pretica non sa cosa andarmi ad
    aprire

  4. #4
    Utente di HTML.it
    Registrato dal
    Apr 2002
    Messaggi
    271
    Devo forse creare un funzione che mi sposti i dati dal database
    allo schermo

    Private Sub dbREc_MoveComplete(ByVal adReason As ADODB.EventReasonEnum,ByVal pError As ADODB.Error,adStatus As ADODB.EventStatusEnum,ByVal pRecordset As ADODB.Recordset)
    txtCognome= dbRec("Cognome")
    txtCognome.DataChanged=False
    End Sub

  5. #5
    Utente bannato
    Registrato dal
    Mar 2002
    Messaggi
    1,811
    ehi che cosa è ADODB.EventReasonEnum

    mai visto

  6. #6
    Utente di HTML.it
    Registrato dal
    Apr 2002
    Messaggi
    271
    adReason As ADODB.EventReasonEnum

    mantiene un valore che indica perchè il record viene modificato

  7. #7
    Utente bannato
    Registrato dal
    Mar 2002
    Messaggi
    1,811
    e a cosa ti servirebbe?

    non è meglio se ti lasci un commento a fianco per sapere i vari passaggi che stai facendo (perche lo fai?)

    io non lo uso e non mai avuto l'idea di usarlo guarda i miei sorgenti
    (bozzi di sorgenti) su http://amodio.too.it
    beh che dici li avrei dovuti usare?

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2024 vBulletin Solutions, Inc. All rights reserved.