G
GTi
I have a SQL database and some fields may be null.
This will trow an exeption:
string[] s=new string[10];
s[0]=String.Format("{0}",myReader.GetString(1));
s[1]=String.Format("{0}",myReader.GetString(2));
s[2]=String.Format("{0}",myReader.GetString(3)); // null field
s[3]=String.Format("{0}",myReader.GetString(4));
One solution is to use:
try { s[0]=String.Format("{0}",myReader.GetString(1)); }
catch {}
try { s[1]=String.Format("{0}",myReader.GetString(2)); }
catch {}
try { s[2]=String.Format("{0}",myReader.GetString(3)); }
catch {}
try { s[3]=String.Format("{0}",myReader.GetString(4)); }
catch {}
Is there a better way to solve null fields ?
This will trow an exeption:
string[] s=new string[10];
s[0]=String.Format("{0}",myReader.GetString(1));
s[1]=String.Format("{0}",myReader.GetString(2));
s[2]=String.Format("{0}",myReader.GetString(3)); // null field
s[3]=String.Format("{0}",myReader.GetString(4));
One solution is to use:
try { s[0]=String.Format("{0}",myReader.GetString(1)); }
catch {}
try { s[1]=String.Format("{0}",myReader.GetString(2)); }
catch {}
try { s[2]=String.Format("{0}",myReader.GetString(3)); }
catch {}
try { s[3]=String.Format("{0}",myReader.GetString(4)); }
catch {}
Is there a better way to solve null fields ?