Click here to Skip to main content
16,015,077 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
please have a look to this XAML:

SQL
<ComboBox Grid.Row="1" Grid.Column="3" Name="cmbNazionalitaProp" Width="230" Margin="0,5,20,2"
ItemsSource="{Binding}" IsSynchronizedWithCurrentItem="True" SelectedValuePath = "codice"
DisplayMemberPath="descrizione" SelectedValue="{Binding Path=nazionalitam,Mode=TwoWay,UpdateSourceTrigger=LostFocus}"/>


and to the property definition in my class:

VB
Private _nazionalitam As Nullable(Of Int32)
Public Property nazionalitam() As Nullable(Of Int32)
    Get
        Return _nazionalitam
    End Get
    Set(ByVal value As Nullable(Of Int32))
        _nazionalitam = value
        NotifyPropertyChange("nazionalitam")
    End Set
End Property


I don't know why the _nazionalitam return value is equal to zero even if the value in the database field is NULL.

Anybody can help me?
Thank you very much
Gae



VB
Public Function getAllNazionalita() As ObservableCollection(Of Nazionalita)
    Dim lNazionalita As New ObservableCollection(Of Nazionalita)
    Dim Nazionalita As Nazionalita
    'lNazionalita.Add(Nothing)
    Try
        tempDataReader = SelectData("SELECT * FROM TGESI_NAZIONALITA WHERE COD_ENTE = '" & codEnte & "' ORDER BY CODICE")
        If tempDataReader.HasRows Then
            Do While tempDataReader.Read
                Nazionalita = New Nazionalita(codEnte,
                                    formattaValore(tempDataReader("CODICE")),
                                    formattaValore(tempDataReader("DESCRIZIONE")),
                                    formattaValore(tempDataReader("SIGLA")))
                lNazionalita.Add(Nazionalita)
            Loop
            tempDataReader.Close()
        End If
    Catch ex As Exception
        MsgBox("Errore nella lettura della lista delle Tratte" & vbCrLf & ex.Message)
        tempDataReader.Close()
        lNazionalita = Nothing
    End Try
    Return lNazionalita
End Function



and in the Load event

Dim NazPropMot As ObservableCollection(Of Nazionalita)

NazPropMot = New ObservableCollection(Of Nazionalita)
NazPropMot = VeiManager.getAllNazionalita
cmbNazionalitaProp.ItemsSource = NazPropMot


Thank you
Gae
Posted
Updated 6-Oct-11 4:43am
v3
Comments
theHollow 19-Sep-11 4:49am    
I need to see the code that puts the value from the database reader or DataTable/DataRow.
Simon Bang Terkildsen 6-Oct-11 10:45am    
The OP has updated the question

1 solution

The Null value from the database will be DBNull in vb.net and not Null. You would need to check if the value is DBNull and return Null if that's true. I'm assuming the function formattaValore does not do that yet or returns 0 if the value is DBNull.

Good luck!
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900