What would be the syntax for putting an array of integers into rows of a DataTable? I know how to do this via a foreach statement, but thought it may be more efficient to do this via LINQ instead. This is what I wrote, but imagine there may be a way to replace the foreach with a LINQ statement.
public static void saveThis(int mainID, int[] userIDList)
{
// The DataTable represents a User-Defined Table Type (IdPair) that
// contains 2 columns of StaticID and VariableID.
DataTable dataTable = new DataTable("IdPair");
dataTable.Columns.Add("StaticID"); // For the mainID
dataTable.Columns.Add("VariableID"); // For the UserIDs
foreach(int userID in userIDList)
{
dataTable.Rows.Add(mainID, userID);
}
// Omitted code to pass dataTable as a Structured object
// to a stored procedure and save changes.
}
Can LINQ replace that foreach statement, and if so, how? Thanks for your help.
=== Edit 3/18/2015 at 1:25 PM Central ===
Thanks everyone for your quick feedback and insight. My apologies for the duplicate. Searches that I performed didn't turn anything up for this (e.g. "linq to put integer array into datatable"). This point I was unaware of, "Basically LINQ is for querying the data not modifying it". Given that, it makes no sense to use LINQ.
A moderator can close this. Thanks.