public Employee Get() { SqlDataReader reader = null; SqlConnection myConnection = new SqlConnection(); myConnection.ConnectionString = @"Data Source=Demo\SQLEXPRESS;Initial Catalog=DB;User ID=xyz;Password=xyz123;Connection Timeout=1800;"; SqlCommand sqlCmd = new SqlCommand(); sqlCmd.CommandType = CommandType.Text; string jsonOutputParam = "@jsonOutput"; //sqlCmd.CommandText = "Create_JSON_ProjectList"; //sqlCmd.Parameters.Add(jsonOutputParam, SqlDbType.NVarChar, -1).Direction = ParameterDirection.Output; sqlCmd.Connection = myConnection; myConnection.Open(); string st = "select projectName from QryProjectWithDepartmentDetails ORDER BY projectName DESC FOR JSON PATH, WITHOUT_ARRAY_WRAPPER"; //FOR JSON PATH, WITHOUT_ARRAY_WRAPPER)"; sqlCmd = new SqlCommand(st, myConnection); reader = sqlCmd.ExecuteReader(); Employee emp = null; while (reader.Read()) { emp = new Employee(); emp.DepartmentNmae = reader["projectName"].ToString(); } return emp; myConnection.Close(); }
using (var myConnection = new SqlConnection("...") using (var sqlCmd = new SqlCommand("select projectName from QryProjectWithDepartmentDetails ORDER BY projectName DESC FOR JSON PATH, WITHOUT_ARRAY_WRAPPER", myConnection)) { myConnection.Open(); var sb = new System.Text.StringBuilder(); using (var reader = sqlCmd.ExecuteReader()) { while (reader.Read()) { sb.Append(reader.GetString(0)); } } return new Employee { DepartmentName = sb.ToString() }; }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)