0
SqlConnection conn = new SqlConnection();
conn.ConnectionString="data source=*;initial catalog=*;User ID=*;Password=*";
conn.Open();

SqlCommand sqlcmd = new SqlCommand(SqlString, conn);

SqlDataReader dr = sqlcmd.ExecuteReader();

How should I use SqlDataReader to get SQL Server values (3 cols and many rows) and turn them into JSON type that Android App can parse it?

Thank you so much!

張信加
  • 1
  • 1
  • Check this out. https://stackoverflow.com/questions/6201529/how-do-i-turn-a-c-sharp-object-into-a-json-string-in-net – drum Jan 29 '19 at 04:12
  • 1
    Possible duplicate of [How do I turn a C# object into a JSON string in .NET?](https://stackoverflow.com/questions/6201529/how-do-i-turn-a-c-sharp-object-into-a-json-string-in-net) – Nathan Champion Jan 29 '19 at 04:19
  • You need to read the entire data from database into an array or a list of anonymous type and then use Newtonsoft JSON library to call JsonConvert.SerializeObject API to convert the list/array to JSON. – mdowes Jan 29 '19 at 04:36
  • Thank you and I want to know more about how to use SqlDataReader and make the result convert into JSON, thank you. – 張信加 Jan 29 '19 at 05:51

0 Answers0