PDA

View Full Version : [VB] Controllo su lettura Database con " IsDBNull "


race2
02-09-2002, 14:29
SU VB.NET:

Questa Sub popola una ListView() multicolonna,

selezionando un rigo si richiama la Sub la cui popola la ListView() e utilizza l'ID che trova nel SubItem della ListView() per eseguire la giusta Query che serve a me.

Cosa sto' sbagliando???

Perche continua a darmi l'errore: " Nessun dato esistente per la riga/colonna. "


Private Sub PopoloDatiCliente()
If lvwResoconto.SelectedItems.Count > 0 Then
Dim ID_Cliente As Integer = lvwResoconto.SelectedItems.Item(0).SubItems(1).Text
conn1.Open()
Dim comm1 As New OleDbCommand("SELECT * FROM Clienti WHERE ID = " & ID_Cliente & "", conn1)
Dim read1 As OleDbDataReader = comm1.ExecuteReader
read1.Read()
If Not IsDBNull(read1("RagSoc")) Then txtRagSoc.Text = read1("RagSoc")
If Not IsDBNull(read1("Nome")) Then txtNome.Text = read1("Nome")
If Not IsDBNull(read1("Cognome")) Then txtCognome.Text = read1("Cognome")
If Not IsDBNull(read1("Indirizzo")) Then txtIndirizzo.Text = read1("Indirizzo")
If Not IsDBNull(read1("Citta")) Then txtCitta.Text = read1("Citta")
If Not IsDBNull(read1("Cap")) Then txtCap.Text = read1("Cap")
If Not IsDBNull(read1("Zona")) Then txtZona.Text = read1("Zona")
If Not IsDBNull(read1("Tel")) Then txtTel.Text = read1("Tel")
If Not IsDBNull(read1("Fax")) Then txtFax.Text = read1("Fax")
If Not IsDBNull(read1("Email")) Then txtEmail.Text = read1("Email")
If Not IsDBNull(read1("Url")) Then txtUrl.Text = read1("Url")
conn1.Close()
End If
End Sub



eppure quella funzione "IsDBNull" serve per ovviare all'errore del campo vuoto nella tabella del Database........

tas
02-09-2002, 20:35
Ma la query è corretta? Sei sicuro che ti restituisce un record?

race2
03-09-2002, 11:44
Certo se sto attento a non salvare record vuoti funziona tutto......