Error occurs when working with table which has an identification
column. Insert method is executed well for tables without an id.
At SqlDataProviderBase.cs at code:
foreach (var memberMapper in members)
bc.ColumnMappings.Add(new
SqlBulkCopyColumnMapping(memberMapper.Ordinal, memberMapper.Name));
"SqlBulkCopyColumnMapping" gets "memberMapper.Ordinal", but if you
have an id column in your table as first column, the first
"memberMapper.Ordinal" value will be 1, next will be 2 and etc.
So, when "WriteToServer" is executing, it calls "object GetValue(int
i)" method, which accesses to the "_members" array. This array
contains n - 1 elements, where "n - 1" - the number of columns in the
table without id. But the value of variable i in the "object
GetValue(int i)" method complies to the value "memberMapper.Ordinal".
The last value of "memberMapper.Ordinal" is "n". But "_members" array
contains "n - 1" elements. It occurs an error.
On 10 фев, 19:39, vladimir matveev <donald...@gmail.com> wrote:
> Hi. I need some help. I tried to use this code:
> using (var db = new BltDataModel())
> {
> var reg = new Collection<FileNames>();
> reg.Add(new FileNames { FileName = "fwqffwqwf",Author
> = "", bProcTime = DateTime.Now, Processed = false});
> ...
> var query = new SqlQuery<FileNames>(db);
> query.Insert(reg);
> }
> But it always crashes at "SqlDataProviderBase.cs" at
> "bc.WriteToServer(rd)". Is it possible to use this type of
> query.Insert?