使用LINQ to SQL SELECT @@ DBTS [英] SELECT @@DBTS using Linq to SQL

查看:156
本文介绍了使用LINQ to SQL SELECT @@ DBTS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何使用LINQ to SQL中使用C#来检索@@ DBTS?

How can I use Linq to SQL to retrieve @@DBTS using C#?

下面是我想:

&IEnumerable的LT; System.Data.Linq.Binary> =结果与db.ExecuteQuery LT; System.Data.Linq.Binary>(@SELECT @@ DBTS);

IEnumerable<System.Data.Linq.Binary> results = db.ExecuteQuery<System.Data.Linq.Binary>(@"SELECT @@DBTS");

然而,这将导致类型System.Data.Linq.Binary必须声明一个默认的(无参数)构造函数,以映射期间建成。

However, this results in "The type 'System.Data.Linq.Binary' must declare a default (parameterless) constructor in order to be constructed during mapping."

如果我尝试使用的byte [],我得到了同样的错误,但以字节[],而不是System.Data.Linq.Binary。

If I try to use byte[], I get the same error but with byte[] instead of System.Data.Linq.Binary.

推荐答案

我怀疑你可能需要使用常规的ADO.NET和的ExecuteReader / ...的ExecuteScalar

I suspect you might have to use regular ADO.NET and ExecuteReader/ExecuteScalar...

        using(SqlConnection conn = new SqlConnection(CONN_STRING))
        using(SqlCommand cmd = conn.CreateCommand())
        {
            cmd.CommandText = "SELECT @@DBTS";
            cmd.CommandType = CommandType.Text;
            conn.Open();
            byte[] ts = (byte[]) cmd.ExecuteScalar();
            foreach (byte b in ts)
            {
                Console.Write(b.ToString("X2"));
            }
            Console.WriteLine();
        }

这篇关于使用LINQ to SQL SELECT @@ DBTS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆