Quantcast
Channel: Windows Presentation Foundation (WPF) forum
Viewing all articles
Browse latest Browse all 18858

Validating data before new object added

$
0
0

I'm not quite sure how to ask this.  Given this code:

            Dim newPatient As New tblPatientDemographic() With { _
                .PatientName = txtPatientName.Text, _
                .MedicalRecordNumber = CType(txtMedicalRecord.Text, Integer?) _
                }
            _context.tblPatientDemographics.Add(newPatient)
            _context.SaveChanges()

it is possible that the medical record number can be blank.  However, if left blank, then an error occurs that a string cannot be converted to integer.  I understand this error but I don't know how to check if it is blank, and if so, then just ignore this. 

Back when I was using winforms, I could do something like this:

.Parameters(10).Value = If(txtMedicalRecordNumber.Text = "", DBNull.Value, txtMedicalRecordNumber.Text)
What would be the way to do this in WPF/EF?


Thanks.


Viewing all articles
Browse latest Browse all 18858

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>