I think the reason of your trouble is this piece of code:
if (!string.IsNullOrWhiteSpace(leavetypeid))
{
string[] arrRay = leavetypeid.Split(',');
foreach (var id in arrRay)
{
if (!string.IsNullOrWhiteSpace(id))
{
iObjects.LEAVE_TYPE_ID = Convert.ToInt32(id);
if (!string.IsNullOrWhiteSpace(leavetypeid))
{
string[] aray_ltype = leavetype.Split(',');
You should replace a second if with:
if (!string.IsNullOrWhiteSpace(leavetype))
I'd suggest to read about
SpringSplitOptions[
^], which may help you to avoid empty entries:
string leavetypeid = "a,b,c,,d,e,f,,,g";
var lids = leavetypeid.Split(new char[]{','}, System.StringSplitOptions.RemoveEmptyEntries);
foreach (var l in lids)
{
Console.WriteLine("{0}", l);
}
Produces:
a
b
c
d
e
f
g
Instead of:
a
b
c
NULL
d
e
NULL
NULL
f
g
Got it?