IT練習ノート

IT関連で調べたこと(実際は嵌ったこと)を書いています。

NTextを指定してもTDSプロトコル用はvarcharになっている

なんでだろう?

using System;
using System.Data;

using System.Data.SqlClient;

namespace ConsoleApp1
{
    class Program1
    {
        static void Main(string[] args)
        {
            using (SqlConnection conn = new SqlConnection())
            {
                conn.ConnectionString = "Server=DESKTOP-PA432R1;Database=TDS;User ID=sa;Password=haskellsa";
                conn.Open();
                SqlCommand command = NewMethod3(conn);
                using (SqlDataReader reader = command.ExecuteReader())
                {
                    Console.WriteLine("FirstColumn\tSecond Column\t\tThird Column\t\tForth Column\t");
                    while (reader.Read())
                    {
                        Console.WriteLine(String.Format("{0} \t | {1} ", reader[0], reader[1]));
                    }
                }
                Console.WriteLine("Data displayed! Now press enter to move to the next section!");
                Console.ReadLine();
                Console.Clear();
            }
            Console.ReadLine();
        }

        private static SqlCommand NewMethod3(SqlConnection conn)
        {
            SqlCommand command = new SqlCommand("select x_id, x_ntext from tds.dbo.tbl_string where x_ntext like @foo", conn);
            SqlParameter param = new SqlParameter("foo", SqlDbType.NText);
            param.Value = "abc"; 
            command.Parameters.Add(param);
            return command;
        }
    }
}

f:id:naotoogawa:20190126152206p:plain
NTextで指定したがパケット上の型はvarcharになっている