in RowsetImportEngine/TextRowsetImporter2.cs [819:892]
private void InsertRow ()
{
bool ret = false;
int ColNum = 0;
object ColData;
foreach (RowsetImportEngine.Column c in CurrentRowset.Columns)
{
// Handle special autonumber column
if (("id"==c.Name) && (c.RowsetLevel))
ColData = this.CurrentRowset.RowsInserted+1;
else
ColData = c.Data;
switch (c.DataType)
{
case SqlDbType.BigInt:
ret = BulkLoad.SetColumnDataBigInt (this.CurrentRowset.hConn, ColNum, (ColData == null)? 0L : (long)ColData, (ColData == null));
break;
case SqlDbType.Int:
ret = BulkLoad.SetColumnDataInt (this.CurrentRowset.hConn, ColNum, (ColData == null)? 0 : (int)ColData, (ColData == null));
break;
case SqlDbType.DateTime:
ret = BulkLoad.SetColumnDataDateTime (this.CurrentRowset.hConn, ColNum, Convert.ToDateTime((string)ColData).ToString("yyyy-MM-dd HH:mm:ss.fff"), (ColData == null));
break;
case SqlDbType.Decimal:
ret = BulkLoad.SetColumnDataDecimal (this.CurrentRowset.hConn, ColNum, (ColData == null)? 0.0M : (decimal)ColData, (ColData == null));
break;
case SqlDbType.Float:
ret = BulkLoad.SetColumnDataFloat (this.CurrentRowset.hConn, ColNum, (ColData == null)? 0.0F : (double)ColData, (ColData == null));
break;
case SqlDbType.NVarChar:
ret = BulkLoad.SetColumnDataNVarChar (this.CurrentRowset.hConn, ColNum, (string)ColData, (ColData == null));
break;
case SqlDbType.VarBinary:
ret = BulkLoad.SetColumnDataVarBinary (this.CurrentRowset.hConn, ColNum, (byte[])ColData, ((ColData == null)? 0 : (ColData as byte[]).GetLength(0)), (ColData == null));
break;
case SqlDbType.VarChar:
ret = BulkLoad.SetColumnDataVarChar (this.CurrentRowset.hConn, ColNum, (string)ColData, (ColData == null));
break;
default:
ErrorDialog ed = new ErrorDialog("Unknown BCP column datatype ["
+ c.DataType.ToString() + "] encountered.", true, this.logger);
ed.Handle();
return;
}
// TODO: If we fail to set row data, log row as failed along with BulkLoad.GetErrorMessage().
ColNum++;
if (!ret)
{
string tmpColData = c.Data.ToString();
string ErrMsg = BulkLoad.GetErrorMessage(this.CurrentRowset.hConn);
tmpColData = tmpColData.Substring (0, (tmpColData.Length < 100) ? tmpColData.Length : 100);
ErrorDialog ed = new ErrorDialog("Error setting BCP column data \"" + tmpColData
+ "\"\n for column [" + c.Name + "].\nDescription: "
+ ErrMsg, true, this.logger);
ed.Handle();
return;
}
}
ret = BulkLoad.SendRow(this.CurrentRowset.hConn);
if (!ret)
{
// TODO: ErrorDialog needs to be enhanced to use ILogger
ErrorDialog ed = new ErrorDialog("Error sending BCP row for table ["
+ this.CurrentRowset.Name + "].\nDescription: "
+ BulkLoad.GetErrorMessage(this.CurrentRowset.hConn), true, this.logger);
ed.Handle();
return;
}
this.CurrentRowset.RowsInserted++;
TotalRowsInserted++;
return;
}