0

我试图在文本框中显示结果 linq 查询显示。我在 SensorDataPackages 表中有 OID、readTime、DeviceID、a_TankLevel1、a_TankLevel2。我想在这样的查询返回后在文本框中显示某些字段的值

Textbox1 = a_TankLevel1;
Textbox2 = a_TankLevel2;

等等。

我得到“SensorData 不为空”。查询正在工作。

//我创建了新的模型数据集

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");
       }
4

1 回答 1

3

尝试String.Join

textbox1.text= String.Join(",", SensorData.Select(a => a.ToString()));

这是假设您的 SensorData 对象已被覆盖ToString()

编辑:

获取最后一个值试试这个

textbox1.text= SensorData.Last().a_TankLevel1.ToString();
于 2013-11-13T09:52:54.657 回答