Reputation: 769
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");
}
Upvotes: 0
Views: 1224
Reputation: 13620
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();
Upvotes: 3