I want to retrieve server datetime, how can I achieve this?
ex. in my sql "select now()" in sql server "select getdate()"
How to execute sql queries command and retrieve its value?
Re: How to execute sql queries command and retrieve its value?
You could do it via the DataContext.ExecuteQuery method, for example:
1) SQL Server:
2) MySQL:
There is also another universal way:
JIC: the NonEmptyTable table - any table that is available in your model, but it must necessarily be non-empty.
1) SQL Server:
Code: Select all
var data = dt.ExecuteQuery<DateTime>("select getdate();");
Code: Select all
var data = dt.ExecuteQuery<DateTime>("select now();");
Code: Select all
var data = dt.NonEmptyTable.Take(1).Select(t => DateTime.Now).First();