I have 3 arrays containing different information. 1 array contains a bunch of id’s, the second array contains a bunch of dates and the third contains a bunch of names.
I know this is a simple question but I cannot remember how to do it so I apologize for the stupidity.
The 3 arrays look like this:
string[] eventIDs = EventID.Split(',');
string[] eventDates = eventCopyDate.Split(',');
string[] invNames = investigatorNames.Split(',');
the values look like “john Doe,Mark Doe, Tim Doe” hence why the .Split
I’ve tried a nested for loop here but no success.
foreach (var id in eventIDs)
{
foreach (var date in eventDates)
{
foreach (var name in invNames)
{
cmd.Parameters.Add(new SqlParameter("@EventID", SqlDbType.Int));
cmd.Parameters["@EventID"].Value = int.Parse(id);
cmd.Parameters.Add(new SqlParameter("@InvestigatorName", SqlDbType.NVarChar));
cmd.Parameters["@InvestigatorName"].Value = name;
cmd.Parameters.Add(new SqlParameter("@CopyDate", SqlDbType.DateTime));
cmd.Parameters["@CopyDate"].Value = Convert.ToDateTime(date);
}//end name foreach
}//end date foreach
}//end id foreach
I know that this will just iterate them through an entire array first before going back to the second nested array. I am trying to iterate to the first value in the array, assign them to the variables then go through the second iteration.
So that arrayNames:”john Doe, Mark Doe” arrayDates”12/12/12, 10/12/12″ and arrayID:”234,235,236″ would be used like:
"john Doe" "12/12/12" "234"
"Mark Doe" "10/12/12" "235"
Don’t use
foreach, just use a normalforloop and use your index to reference your arrays.This assumes that the three arrays are all equal length. If this is not the case then it is slightly more complicated.