trying to get some measurement data to ASP from Microsoft SQL?
-
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
-
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
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