Avatar of Bill Park
Bill Park
Flag for United States of America

asked on 

Take output from SQL Server stored proc and convert output of multiple line resultset into 1 JSON packet in C#

I have a stored procedure that produces output that looks (in SSMS) like this:
Device               Loc   CaptureTime
0000000001D0   9   22:18:05
000000000402   3   22:18:05
00000000016C   7   22:18:05
00000000013D   7   22:18:05

There could be several hundred rows like this.
I need to create a single JSON package  of all of the records in the  SQL resultset in C#.
I know how to connect to the database and execute the stored procedure.
Using the following I get all of the contents of just first column (I think):
           while(rdr.Read())
            {
                String strResultSet = rdr.GetString(0);
                Console.WriteLine("{0}", strResultSet);
           }
I think I need to get DataReader to return all of the columns of each record. I don't know how.
Then, is there a way within DataReader for all records to be appended to strResultSet or will I need to concatenate each new record explicitly?

Please consider me as someone who has not done anything in C# until very recently.

Thank you.

Why fewer and fatter packets? Something to do with how Azure charges for IoTHub messages.

Yes, I'm very new to this.
* ADOSQLC#Microsoft SQL ServerJSON

Avatar of undefined
Last Comment
slightwv (䄆 Netminder)

8/22/2022 - Mon