Question

I tried to display result linq query display in textbox. I have OID, readTime, DeviceID, a_TankLevel1, a_TankLevel2 in SensorDataPackages table. I want to display value of some field in a textbox after query returns like this

Textbox1 = a_TankLevel1;
Textbox2 = a_TankLevel2;

an so forth.

I get "SensorData is not empty".Query is working.

//I created new 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");
       }
Was it helpful?

Solution

Try String.Join

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

This is assuming that your SensorData object has an overridden ToString()

EDIT:

The get the last value try this

textbox1.text= SensorData.Last().a_TankLevel1.ToString();
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top