DateTime c# failing

Hi,

I am not able to insert DateTime through c#. Any suggestions will be helpful.

[TestMethod]

        public void DateInsertTest()

        {

            // Reference http://code.kx.com/wiki/Cookbook/InterfacingWithCSharp

            c qc = new c(this.KdbServerName, this.KdbPortToConnect, “”, 1000000);

            qc.k(“t:(dt:`datetime$())”);

            // works because it is same like q command

            qc.k(“`t insert (” + DateTime.Now.ToString(“yyyy.MM.ddThh:mm:ss”) + “)”);

            // Dont work (Throws type exception)

            qc.k(“insert”, “t”, new object { DateTime.Now });

            // Dont work (Throws type exception)

            qc.k(“insert”, “t”, new object { DateTime.Now.ToString(“yyyy.MM.ddThh:mm:ss”) });

            qc.Close();

        }

Hi Vikas

I’m not a c# expert, but I think the first issue is because you can’t send datetime types from c# anymore - they are timestamp types.  This is from the release notes:

//2010.01.04 Added new time types (timespan->KTimespan,timestamp->DateTime), drop writing kdb+ datetime

For the second failure, I think it’s because you are sending a string from c# and you get a type error because the table expects datetime.

In both cases you can modify the call to get more debug output on the kdb+ side to see what is being received e.g. 

qc.k("{[x;y] 0N!(x;y);x insert y}, “t”, new object{ DateTime.Now.ToString(“yyyy.MM.ddThh:mm:ss”) });

Hope that helps

Andrew Steele

Aquaq Analytics

Thanks Andrew. It helped. I am able to use timestamp for DateTime.