C# 在标签中显示linq查询结果
我试图在文本框中显示结果linq查询显示。SensorDataPackages表中有OID、readTime、DeviceID、a_TankLevel1和a_TankLevel2。我想在查询返回后在文本框中显示某个字段的值,如下所示C# 在标签中显示linq查询结果,c#,linq,datacontext,C#,Linq,Datacontext,我试图在文本框中显示结果linq查询显示。SensorDataPackages表中有OID、readTime、DeviceID、a_TankLevel1和a_TankLevel2。我想在查询返回后在文本框中显示某个字段的值,如下所示 Textbox1 = a_TankLevel1; Textbox2 = a_TankLevel2; 等等 我得到“传感器数据不为空”。查询正在运行 //我创建了新的modeldataset private string istDeviceID = ""; M
Textbox1 = a_TankLevel1;
Textbox2 = a_TankLevel2;
等等
我得到“传感器数据不为空”。查询正在运行
//我创建了新的modeldataset
private string istDeviceID = "";
MyWebApplication.MyClasses.ModelDataContext MyNewModel= new MyWebApplication.MyClasses.ModelDataContext();
this.istDeviceID = ComboBox1.SelectedItem.GetValue("DeviceID").ToString();
DateTime SensorDateNow= DateTime.Now;
DateTime SensorDate= DateTime.Now.AddDays(-7);
var SensorData = (from Sensor in MyNewModel.SensorDataPackages
where Sensor.DeviceID == int.Parse(istDeviceID)
where Sensor.readTime.Date >= SensorDateNow.Date
where Sensor.readTime.Date <= SensorDate.Date
select Sensor).ToList();
if (SensorData.Count > 0)
{
MessageBox.Show("SensorData is not empty");
textbox1.text = SensorData.?????? // I need help here !!!
}
else
{
MessageBox.Show("SensorData is empty");
}
私有字符串istDeviceID=”“;
MyWebApplication.MyClasses.ModelDataContext MyNewModel=新建MyWebApplication.MyClasses.ModelDataContext();
this.istDeviceID=ComboBox1.SelectedItem.GetValue(“DeviceID”).ToString();
DateTime SensorDateNow=DateTime.Now;
DateTime SensorDate=DateTime.Now.AddDays(-7);
var SensorData=(来自MyNewModel.SensorDataPackages中的传感器
其中Sensor.DeviceID==int.Parse(istDeviceID)
其中Sensor.readTime.Date>=SensorDateNow.Date
其中Sensor.readTime.Date 0)
{
MessageBox.Show(“传感器数据不为空”);
textbox1.text=传感器数据?????//我需要帮助!!!
}
其他的
{
MessageBox.Show(“传感器数据为空”);
}
试试看
这是假设您的SensorData对象有一个覆盖的ToString()
编辑:
获取最后一个值时,请尝试以下操作
textbox1.text= SensorData.Last().a_TankLevel1.ToString();
试一试
这是假设您的SensorData对象有一个覆盖的ToString()
编辑:
获取最后一个值时,请尝试以下操作
textbox1.text= SensorData.Last().a_TankLevel1.ToString();
试一试
这是假设您的SensorData对象有一个覆盖的ToString()
编辑:
获取最后一个值时,请尝试以下操作
textbox1.text= SensorData.Last().a_TankLevel1.ToString();
试一试
这是假设您的SensorData对象有一个覆盖的ToString()
编辑:
获取最后一个值时,请尝试以下操作
textbox1.text= SensorData.Last().a_TankLevel1.ToString();
我尝试了textbox1.text=String.Join(“,”,SensorData.Select(a=>a.ToString())和textbox1.text=String.Join(“,”,SensorData.Select(a=>a.a_TankleLevel 1.ToString());但是textbot是空的。你能为
SensorData
textbox1.text=SensorData.ToString();结果:System.Collections.Generic.List`1发布ToString中的内容吗[MyWebApplication.MyClasess.SensorDataPackage]你在你的类中重写了ToString
吗?我在我的类中没有重写ToString我尝试了textbox1.text=String.Join(,),SensorData.Select(a=>a.ToString())和textbox1.text=String.Join(,),SensorData.Select(a=>a.a\u TankleLevel 1.ToString());但是textbot是空的。您可以发布SensorData
Textbox1.Text=SensorData.ToString();结果:System.Collections.Generic.List`1[MyWebApplication.myclases.SensorDataPackage]你在你的类中重写了ToString
了吗?我的类中没有重写ToString我尝试了textbox1.text=String.Join(“,”,SensorData.Select(a=>a.ToString())和textbox1.text=String.Join(“,”,SensorData.Select(a=>a.a\u TankLevel1.ToString());但是textbot是空的。您可以发布SensorData
Textbox1.Text=SensorData.ToString();结果:System.Collections.Generic.List`1[MyWebApplication.myclases.SensorDataPackage]你在你的类中重写了ToString
了吗?我的类中没有重写ToString我尝试了textbox1.text=String.Join(“,”,SensorData.Select(a=>a.ToString())和textbox1.text=String.Join(“,”,SensorData.Select(a=>a.a\u TankLevel1.ToString());但是textbot是空的。你能为SensorData
Textbox1.Text=SensorData.ToString()发布ToString
中的内容吗?结果:System.Collections.Generic.List`1[MyWebApplication.myclases.SensorDataPackage]你在你的类中重写了ToString
了吗?我的类中没有重写ToString