Click here to Skip to main content
15,881,092 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have this in c#
C#
string jsonResultado = await Clases.AccesoDatos.JsonData("SELECT * FROM vistatransacciones for json path, ROOT('product.json')");

where method jsonData is:
  public static async Task<string> JsonData(string SQL)
        {
            string json = "";
            using (SqlConnection con = new SqlConnection(cadenaConexion))
            {
                SqlCommand cmd = new SqlCommand(SQL, con);
                await con.OpenAsync();
                SqlDataReader dr = await cmd.ExecuteReaderAsync();                
                if (dr.HasRows)
                {
                    DataTable jsondt = dr.GetSchemaTable();                    
                    json= JsonConvert.SerializeObject(jsondt);
                }
                
                dr.Close();
            }
            
            return json;
        }


In fact, after the if(dr.hasrows) i do not know what to do, i just want to read following result in my program:
{"Product.json":
[{"idRegistro":1,
"idUsuario":"1",
"FechaRegistro":"2023-01-18T11:29:23.030",
.....

But i do not know how to return the value

What I have tried:

codeproject paper, manuals, microsoft
Posted
Updated 2-Feb-23 5:27am
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900