开发者

Creating Data Table from object array

I am not sure if I am going about this the correct way but I have a c# method which loads an excel sheet into a 2 dimentional object array. In this array item 1,1 - 1,16 contain headers, then 2-1 - 2-16 contain data that match up with those headers as do x-1 - x-16 from there on in. I would like to turn this array into a data table so ultimately I can have it in a format I will then import into an access or SQL server db depending on a clients needs. I have tried using the following code to no avail, but I have a feeling I am way off. Any help on this would be very much appreciated.

private void ProcessObjects(object[,] valueArray)
{
    DataTable h开发者_JAVA技巧oldingTable = new DataTable();
    DataRow holdingRow;
    holdingTable.BeginLoadData();
    foreach(int row in valueArray)
    {
        holdingRow = holdingTable.LoadDataRow(valueArray[row], true);
    }
}


Any chance you're using a repository pattern (like subsonic or EF) or using LinqToSql?

You could do this (LinqToSql for simplicity):

List<SomeType> myList = valueArray.ToList().Skip([your header rows]).ConvertAll(f => Property1 = f[0] [the rest of your convert statement])
DataContext dc = new DataContext();

dc.SomeType.InsertAllOnSubmit(myList);
dc.SubmitChanges();
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜