how to write method that return datatable in CLR C#


  • I have specific CLASS (.DLL) that only return datatable method and I am calling in CLR like below ,But I have a OUTPUT result problem .

    // CLR Method

     public static void DtMethodClr()  
        var dt = Postbox.DtMethod("SELECT TOP 4 NAME,STATE_DESC FROM SYS.DATABASES");
        for (int i = 0; i < dt.Rows.Count; i++)
          if (SqlContext.Pipe != null) SqlContext.Pipe.Send(dt.Rows[i][0] + dt.Rows[i][1].ToString());

    But When exec method the result like below


    the problem is ,

    1 - column name not visible

    2 - Align not regular

    • Edited by Aly14 Thursday, April 20, 2017 8:28 AM
    Thursday, April 20, 2017 8:26 AM

All replies

  • Pipe.Send(string) is for sending messages to the client, not resultsets.

    You need to use one of the other methods here:  SqlPipe Class and either send individual records, or a whole SqlDataReader.


    Microsoft Technology Center - Dallas
    My blog

    Thursday, April 20, 2017 1:36 PM