BAE BAE - 7 months ago 7
Vb.net Question

why 0, not Nothing in VB System.Data.DataTable

The codes:

Private m_log_dataTable As System.Data.DataTable = Nothing
Private m_freq As String = Nothing
Private m_r As Single = Nothing
Private m_l As Single = Nothing
Private m_c As Single = Nothing
Private m_rp As Single = Nothing
Private m_rs As Single = Nothing
Private m_z As Single = Nothing
Private m_esr As Single = Nothing
Private m_dcr As Single = Nothing
Private m_q As Single = Nothing
Private m_d As Single = Nothing


...

Private Sub LOG()
Try
m_freq = Nothing
m_r = Nothing
m_l = Nothing
m_c = Nothing
m_rp = Nothing
m_rs = Nothing
m_z = Nothing
m_esr = Nothing
m_dcr = Nothing
m_q = Nothing
m_d = Nothing
m_value = Nothing
m_unit = Nothing
m_log_dataTable.Rows.Add(DateTime.Now, getDUT(), getMode(), m_freq, m_r, m_l, m_c, m_r, m_rs, m_z, m_esr, m_dcr, m_q, m_d)'Line1
m_log_dataTable.Rows.Add(DateTime.Now, getDUT(), getMode(), Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing)'Line2
Catch ex As Exception
MsgBox("Exception when logging:" + ex.Message)
End Try
End Sub


Output:
enter image description here

Why line1 (in the above codes) write 0 to the datatable instead of Nothing?
What should I do?

Thanks

Answer

You need to use a Nullable type. Change all of your single types to single? and try it again.

Private m_r As Single? = Nothing
Private m_l As Single? = Nothing

// etc