• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1308
  • Last Modified:

Input string was not in a correct format

I am reading data from a table and and determined that one of the fields is a blank.  My variable I am trying to store this data to is an integer.  I am doing a Convert.ToInt32 but it does not know how to handle a blank field.  I tried putting a .ToString at the end of the data but that did not work either.  Can someone tell me the syntax to hand blank fields?
MyGlobalVars.initGuid = Guid.NewGuid();
                myMPI.MPI1 = MyGlobalVars.initGuid;
 
                myMPI.NPI = Convert.ToInt32(patient.d.NPI.ToString());--------  Error Here

Open in new window

0
kwh3856
Asked:
kwh3856
1 Solution
 
reb73Commented:
Convert.ToInt32(patient.d.NPI ?? 0);
0
 
sandygettingsCommented:
Try

myMPI.NPI = Convert.ToInt32(IIf(String.IsNullOrEmpty(patient.d.NPI.ToString),0,patient.d.NPI.ToString)

This will supply a default value (e.g., zero) if the field is blank.

0
 
naspinskiCommented:
reb's is the cleanest route, '??' means if the left side if it is not null, but if it is null, use the right side
0
 
kwh3856Author Commented:
Reb,
Thank you very much.
0

Featured Post

Granular recovery for Microsoft Exchange

With Veeam Explorer for Microsoft Exchange you can choose the Exchange Servers and restore points you’re interested in, and Veeam Explorer will present the contents of those mailbox stores for browsing, searching and exporting.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now