0

When I'm quering in PHP something like that:

SELECT `ID`, `Name`, `EmailAddress` FROM `Accounts` WHERE `ID` = {$id}

I will return the result something in this sturcture:

{
    "ID":1,
    "EmailAddress":"banana@scale.com",
    "Name":"Joseph"
}

When I'm quering in C# like that:

SqlCommand cmd = new SqlCommand("SELECT [ID], [Name], [EmailAddress] FROM [Accounts] WHERE [ID] = @ID", con);

cmd.Parameters.Add(new SqlParameter("@ID", id.ToString()));


SqlDataReader reader = cmd.ExecuteReader();

It'll return something in this sturcture:

(
    0 : 1,
    1 : "Joseph",
    2 : "banana@scale.com"
)

My question is : how can I make the same sturcture in c#?

Itay
  • 337
  • 5
  • 22
  • You mean like a hashmap/dictionary? See http://stackoverflow.com/questions/912948/sqldatareader-how-to-convert-the-current-row-to-a-dictionary – CodeCaster Oct 31 '14 at 11:57
  • This might be helpful: http://stackoverflow.com/questions/1464883/how-can-i-easily-convert-datareader-to-listt – Mahmoud Gamal Oct 31 '14 at 11:59

1 Answers1

0

If you mean a valid JSON that you have to look at Newtonsoft JSON library

Use JsonConvert class:

string json = JsonConvert.SerializeObject(yourObjectToSerializeToJSON);
Michael
  • 1,027
  • 10
  • 22