private async Task <IList> GetItensNovos() { ArrayList resultado = new ArrayList(); try { string sql = null; sql = "select * from TODOS.dbo.REGISTROS where status = 'nv';"; SqlCommand command; SqlDataReader dataReader; using (SqlConnection connection = new SqlConnection(WebConfigurationManager.ConnectionStrings["ConnStringDb1"].ConnectionString)) { connection.Open(); command = new SqlCommand(sql, connection); dataReader = command.ExecuteReader(); while (dataReader.Read()) { System.Diagnostics.Debug.WriteLine(dataReader.GetValue(0)); DateTime thisDay = DateTime.Now; var itemID = dataReader.GetValue(0).ToString(); var itemNoome = dataReader.GetValue(1).ToString(); var itemCarr = dataReader.GetValue(2).ToString(); var agora = thisDay.ToString(); var RegintroString = new TBL_Regitros() { Id = Convert.ToInt32(itemID), Name = itemNoome, Car = itemCarr, Agora = agora }; resultado.Add(RegintroString); } dataReader.Close(); command.Dispose(); connection.Close(); } } catch (SqlException e) { Console.WriteLine(e.ToString()); } //var jsonRes = Json(resultado); return(resultado); }
public JsonResult <IList> Selec01() { IList resultado = new ArrayList(); string conectStatus = "erro"; try { string sql = null; sql = "select * from TODOS.dbo.REGISTROS;"; SqlCommand command; SqlDataReader dataReader; //var BD_Registros = new TBL_Regitros(); /// var RegintroString = new TBL_Regitros() { Id = 12, Name = "json rest ok", Car = "" }; // resultado.Add(RegintroString); // Connect to SQL Console.Write("Connecting to SQL Server ... "); using (SqlConnection connection = new SqlConnection(WebConfigurationManager.ConnectionStrings["ConnStringDb1"].ConnectionString)) { connection.Open(); conectStatus = "conectado con sucesso " + " Database = " + connection.Database; Console.WriteLine("Done."); command = new SqlCommand(sql, connection); dataReader = command.ExecuteReader(); while (dataReader.Read()) { System.Diagnostics.Debug.WriteLine(dataReader.GetValue(0) + " - " + dataReader.GetValue(1) + " - " + dataReader.GetValue(2)); DateTime thisDay = DateTime.Now; var itemID = dataReader.GetValue(0).ToString(); var itemNoome = dataReader.GetValue(1).ToString(); var itemCarr = dataReader.GetValue(2).ToString(); var agora = thisDay.ToString(); var RegintroString = new TBL_Regitros() { Id = Convert.ToInt32(itemID), Name = itemNoome, Car = itemCarr, Agora = agora }; resultado.Add(RegintroString); } dataReader.Close(); command.Dispose(); connection.Close(); } } catch (SqlException e) { conectStatus = "erro"; Console.WriteLine(e.ToString()); } Console.WriteLine("All done. Press any key to finish..."); var jsonString = Json(resultado); return(jsonString); }