Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. Web Development
  3. ASP.NET
  4. trying to get some measurement data to ASP from Microsoft SQL?

trying to get some measurement data to ASP from Microsoft SQL?

Scheduled Pinned Locked Moved ASP.NET
csharpdatabasesysadminasp-netvisual-studio
2 Posts 2 Posters 5 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    auting82
    wrote on last edited by
    #1

    Hi, I am trying to get some temperature measurement data that I have stored in a SQL data base over on a webpage through asp.net. Instead of getting timestamp with temperature measurement numbers I am getting some code text. Here is my C# code in asp.net This is Measurement.cs file Am working in Microsoft Visual studio:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Threading.Tasks;
    using System.Data.SqlClient;
    using Microsoft.JSInterop.Infrastructure;
    using Microsoft.AspNetCore.Hosting.Server;
    using System.Threading.Tasks;

    namespace AirHeaterControlSystem.Models
    {
    public class Measurement
    {
    public string Timestamp { get; set;}
    public string MeasurementValue { get; set; }
    public string ControlValue { get; set; }

        public List GetMeasurementParameters()
        {
            List measurmentParameterList = new List();
            string connectionString = "DATA SOURCE=LAPTOP-1T8PALVT\\\\CITADEL;UID=LAPTOP-1T8PALVT\\\\AdisP;DATABASE=MEASUREMENTDATA;Integrated Security = True;" ;
            SqlConnection con = new SqlConnection(connectionString);
            string sqlQuery = "Select Timestamp,MeasurementValue,ControlValue from MEASUREMENTDATA";
            con.Open();
    
            SqlCommand cmd = new SqlCommand(sqlQuery, con);
    
            SqlDataReader dr = cmd.ExecuteReader();
    
            if (dr != null)
            {
                while (dr.Read())
                {
                    /\*Measurement ChartValues = new Measurement();
                    ChartValues.ChartYvalue= Convert.ToDouble(dr\[\])\*/
    
                    
                    Measurement measurementParameter = new Measurement();
                    
                    measurementParameter.Timestamp = dr\["TimeStamp"\].ToString();
    
                    measurementParameter.MeasurementValue = dr\["MeasurementValue"\].ToString();
                    measurementParameter.ControlValue = dr\["ControlValue"\].ToString();
    
                    measurmentParameterList.Add(measurementParameter);                  
    
                }
            }
    
            return measurmentParameterList;       
        }
    
    }
    

    }

    Here is my cshtml file,

    @page
    @model AirHeaterControlSystem.Pages.MeasurementModel
    @{
    ViewData["Title"] = "Measurement Parameters";

    }

    Airheater temperature measurement

    Richard DeemingR 1 Reply Last reply
    0
    • A auting82

      Hi, I am trying to get some temperature measurement data that I have stored in a SQL data base over on a webpage through asp.net. Instead of getting timestamp with temperature measurement numbers I am getting some code text. Here is my C# code in asp.net This is Measurement.cs file Am working in Microsoft Visual studio:

      using System;
      using System.Collections.Generic;
      using System.Linq;
      using System.Threading.Tasks;
      using System.Data.SqlClient;
      using Microsoft.JSInterop.Infrastructure;
      using Microsoft.AspNetCore.Hosting.Server;
      using System.Threading.Tasks;

      namespace AirHeaterControlSystem.Models
      {
      public class Measurement
      {
      public string Timestamp { get; set;}
      public string MeasurementValue { get; set; }
      public string ControlValue { get; set; }

          public List GetMeasurementParameters()
          {
              List measurmentParameterList = new List();
              string connectionString = "DATA SOURCE=LAPTOP-1T8PALVT\\\\CITADEL;UID=LAPTOP-1T8PALVT\\\\AdisP;DATABASE=MEASUREMENTDATA;Integrated Security = True;" ;
              SqlConnection con = new SqlConnection(connectionString);
              string sqlQuery = "Select Timestamp,MeasurementValue,ControlValue from MEASUREMENTDATA";
              con.Open();
      
              SqlCommand cmd = new SqlCommand(sqlQuery, con);
      
              SqlDataReader dr = cmd.ExecuteReader();
      
              if (dr != null)
              {
                  while (dr.Read())
                  {
                      /\*Measurement ChartValues = new Measurement();
                      ChartValues.ChartYvalue= Convert.ToDouble(dr\[\])\*/
      
                      
                      Measurement measurementParameter = new Measurement();
                      
                      measurementParameter.Timestamp = dr\["TimeStamp"\].ToString();
      
                      measurementParameter.MeasurementValue = dr\["MeasurementValue"\].ToString();
                      measurementParameter.ControlValue = dr\["ControlValue"\].ToString();
      
                      measurmentParameterList.Add(measurementParameter);                  
      
                  }
              }
      
              return measurmentParameterList;       
          }
      
      }
      

      }

      Here is my cshtml file,

      @page
      @model AirHeaterControlSystem.Pages.MeasurementModel
      @{
      ViewData["Title"] = "Measurement Parameters";

      }

      Airheater temperature measurement

      Richard DeemingR Offline
      Richard DeemingR Offline
      Richard Deeming
      wrote on last edited by
      #2

      Well, your view is wrong to start with. You've put:

      <td> "measurement.Timestamp</td>

      when it should be:

      <td> @measurement.Timestamp</td>

      You should also be wrapping the disposable objects in a using block:

      public List<Measurement> GetMeasurementParameters()
      {
      const string connectionString = "DATA SOURCE=LAPTOP-1T8PALVT\\CITADEL;UID=LAPTOP-1T8PALVT\\AdisP;DATABASE=MEASUREMENTDATA;Integrated Security = True;" ;
      const string sqlQuery = "Select Timestamp, MeasurementValue, ControlValue from MEASUREMENTDATA";

      List<Measurement> measurmentParameterList = new List<Measurement>();
      using (SqlConnection con = new SqlConnection(connectionString))
      using (SqlCommand cmd = new SqlCommand(sqlQuery, con))
      {
          con.Open();
          using (SqlDataReader dr = cmd.ExecuteReader())
          {
              while (dr.Read())
              {
                  Measurement measurementParameter = new Measurement();
                  measurementParameter.Timestamp = dr\["TimeStamp"\].ToString();
                  measurementParameter.MeasurementValue = dr\["MeasurementValue"\].ToString();
                  measurementParameter.ControlValue = dr\["ControlValue"\].ToString();
                  measurmentParameterList.Add(measurementParameter);                  
              }
          }
      }
      
      return measurmentParameterList;       
      

      }

      Beyond that, we can't help you. You haven't told us what you mean by "some code text", and you haven't shown us any of the data from your database.


      "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

      "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups