R
Richard A. DeVenezia
My C# program reads a proprietary binary file into a DataTable, of
which one of the columns (elapsedTime) is a TimeSpan.
elapsedTime ranges from 10hours to 5 days at a precision of 1/100th of
second.
The data table needs to be bulk copied to a SQL Server table.
Any advice on how the SQL table should be constructed is appreciated.
Tried:
Sql server management studio:
---
create table [timespan] with columns
- id int {identity=true;seed=1;incr=1}
- elapsedTime bigint
C#
---
DataTable t = new DataTable();
DataColumn e = new DataColumn("elapsedTime");
e.DataType = System.Type.GetType("System.TimeSpan");
t.Columns.Add(e);
t.Rows.Add()[0] = new TimeSpan ((long)( (0*3600 + 0*60 + 4.52) *
TimeSpan.TicksPerSecond)); // 0:0:4.52
t.Rows.Add()[0] = new TimeSpan ((long)( (0*3600 + 0*60 + 12.5) *
TimeSpan.TicksPerSecond)); // 0:0:12.50
t.Rows.Add()[0] = new TimeSpan ((long)( (72*3600 + 30*60 + 15) *
TimeSpan.TicksPerSecond)); // 72:30:15.00
SqlBulkCopy sbc = new SqlBulkCopy(db);
sbc.DestinationTableName = "timespan";
try
{
sbc.WriteToServer(t);
}
catch (Exception ex)
{
Logger(ex.Message);
}
No exceptions were thrown, and strangely, no rows were written (bulk
copied) to [timespan]
which one of the columns (elapsedTime) is a TimeSpan.
elapsedTime ranges from 10hours to 5 days at a precision of 1/100th of
second.
The data table needs to be bulk copied to a SQL Server table.
Any advice on how the SQL table should be constructed is appreciated.
Tried:
Sql server management studio:
---
create table [timespan] with columns
- id int {identity=true;seed=1;incr=1}
- elapsedTime bigint
C#
---
DataTable t = new DataTable();
DataColumn e = new DataColumn("elapsedTime");
e.DataType = System.Type.GetType("System.TimeSpan");
t.Columns.Add(e);
t.Rows.Add()[0] = new TimeSpan ((long)( (0*3600 + 0*60 + 4.52) *
TimeSpan.TicksPerSecond)); // 0:0:4.52
t.Rows.Add()[0] = new TimeSpan ((long)( (0*3600 + 0*60 + 12.5) *
TimeSpan.TicksPerSecond)); // 0:0:12.50
t.Rows.Add()[0] = new TimeSpan ((long)( (72*3600 + 30*60 + 15) *
TimeSpan.TicksPerSecond)); // 72:30:15.00
SqlBulkCopy sbc = new SqlBulkCopy(db);
sbc.DestinationTableName = "timespan";
try
{
sbc.WriteToServer(t);
}
catch (Exception ex)
{
Logger(ex.Message);
}
No exceptions were thrown, and strangely, no rows were written (bulk
copied) to [timespan]