Linq Query Limitations, more than one query fails
-
Hello: I simply want to write multiple queries to assign information.
var q = from a1 in dt\_Jobs.AsEnumerable() orderby a1.Field("Customer") select a1.Field("Customer"); var lstCustomer = q.Distinct().ToList(); cboCustomer.DataSource = lstCustomer; q = from a1 in dt\_Jobs.AsEnumerable() orderby a1.Field("City") select a1.Field("City"); var lstCity = q.Distinct().ToList(); cboCity.DataSource = lstCity;
The first block works, the second fails. How can I achieve something like this?? Thanks!
-
Hello: I simply want to write multiple queries to assign information.
var q = from a1 in dt\_Jobs.AsEnumerable() orderby a1.Field("Customer") select a1.Field("Customer"); var lstCustomer = q.Distinct().ToList(); cboCustomer.DataSource = lstCustomer; q = from a1 in dt\_Jobs.AsEnumerable() orderby a1.Field("City") select a1.Field("City"); var lstCity = q.Distinct().ToList(); cboCity.DataSource = lstCity;
The first block works, the second fails. How can I achieve something like this?? Thanks!
You're going to have to explain what "fails" means. Did it throw an exception? What was the message? Does something not work as expected? How so and under what conditions?
Asking questions is a skill CodeProject Forum Guidelines Google: C# How to debug code Seriously, go read these articles.
Dave Kreskowiak -
You're going to have to explain what "fails" means. Did it throw an exception? What was the message? Does something not work as expected? How so and under what conditions?
Asking questions is a skill CodeProject Forum Guidelines Google: C# How to debug code Seriously, go read these articles.
Dave KreskowiakI am trying to set the datasources for comboboxes. There is a datasource in the first, but not in the second. If I flip them around, I get the opposite effect.
-
I am trying to set the datasources for comboboxes. There is a datasource in the first, but not in the second. If I flip them around, I get the opposite effect.
Sorry for the confusion, there are errors. Exception thrown: 'System.FormatException' in mscorlib.dll Exception thrown: 'System.NullReferenceException' in ResourcePlanningC2.exe Exception thrown: 'System.InvalidCastException' in mscorlib.dll Exception thrown: 'System.NullReferenceException' in ResourcePlanningC2.exe Exception thrown: 'System.FormatException' in mscorlib.dll Exception thrown: 'System.NullReferenceException' in ResourcePlanningC2.exe Exception thrown: 'System.NullReferenceException' in ResourcePlanningC2.exe Exception thrown: 'System.FormatException' in mscorlib.dll The program '[12772] ResourcePlanningC2.exe' has exited with code -1 (0xffffffff). It must be hanging on some null values. Is there an easy way to handle this?
-
Sorry for the confusion, there are errors. Exception thrown: 'System.FormatException' in mscorlib.dll Exception thrown: 'System.NullReferenceException' in ResourcePlanningC2.exe Exception thrown: 'System.InvalidCastException' in mscorlib.dll Exception thrown: 'System.NullReferenceException' in ResourcePlanningC2.exe Exception thrown: 'System.FormatException' in mscorlib.dll Exception thrown: 'System.NullReferenceException' in ResourcePlanningC2.exe Exception thrown: 'System.NullReferenceException' in ResourcePlanningC2.exe Exception thrown: 'System.FormatException' in mscorlib.dll The program '[12772] ResourcePlanningC2.exe' has exited with code -1 (0xffffffff). It must be hanging on some null values. Is there an easy way to handle this?
I think I got it, Thanks for the help!
var q =
from a1 in dt_Jobs.AsEnumerable()
orderby a1.Field("City")
where (a1.Field("City") != null)
select a1.Field("City");
var lstCity = q.Distinct().ToList();
cboCity.DataSource = lstCity;