C# and SQL Server DateTime Conversion

C

Chris

Hello,

I'm having some problems right now with something that would seem to be
rather simple (and probably is). But, the solution is escaping me right
now.

Currently, I have created a data structure with a timestamp in it. This is
created in a DLL written in C++. The command that I use to get the
timestamp is:

GetSystemTimeAsFileTime(LPFILETIME lpSystemTimeAsFileTime)

At the other end, I have an SQL Server database. Within a table, I have a
column named 'TSTAMP' with a Data Type of 'datetime'.

Between the dll and server, I have a C# application to retrieve the
information from the DLL and add it to the database. However, I'm having
problems figuring out the correct conversion. I know that the 'datetime'
datatype is different from that in .net.

When I retrieve the data from the dll, I execute the following command on
the timestamp:

DateTime.FromFileTime(myEvent.timestamp);

Then, I go to add it to the database but get an error. I've tried casting
it, etc. but to no avail. I also found the SqlDateTime structure but I
don't know how to apply it to DateTime so I can add the data to the
database.

Would you happen to have any suggestions?

Thanks in advance,

Chris
 
C

Chris

Chris said:
Hello,

I'm having some problems right now with something that would seem to be
rather simple (and probably is). But, the solution is escaping me right
now.

Currently, I have created a data structure with a timestamp in it. This is
created in a DLL written in C++. The command that I use to get the
timestamp is:

GetSystemTimeAsFileTime(LPFILETIME lpSystemTimeAsFileTime)

At the other end, I have an SQL Server database. Within a table, I have a
column named 'TSTAMP' with a Data Type of 'datetime'.

Between the dll and server, I have a C# application to retrieve the
information from the DLL and add it to the database. However, I'm having
problems figuring out the correct conversion. I know that the 'datetime'
datatype is different from that in .net.

When I retrieve the data from the dll, I execute the following command on
the timestamp:

DateTime.FromFileTime(myEvent.timestamp);

Then, I go to add it to the database but get an error. I've tried casting
it, etc. but to no avail. I also found the SqlDateTime structure but I
don't know how to apply it to DateTime so I can add the data to the
database.

Would you happen to have any suggestions?

Thanks in advance,

Chris
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top