In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly explains the "LINQ operation DataTable specified conversion invalid problem how to solve", the article explains the content is simple and clear, easy to learn and understand, the following please follow the editor's ideas slowly in-depth, together to study and learn "LINQ operation DataTable specified conversion invalid problem how to solve" it!
Code
Public static IEnumerable getEnumerable () {DataTable dt = getDatatable () Try {var query = from q in dt.AsEnumerable () where q.Field ("IPLocation") = "Pure Network June 20, 2008 IP data" select new {IPid = q.Field ("IPid"), IPFrom = q.Field ("IPFrom"), IPTo = q.Field ("IPTo"), IPCity = q.Field ("IPCity"), IPToNumber = q.Field ("IPToNumber") IPFromNumber = q.Field ("IPFromNumber")} Return query;} catch {return null;}}
Then when I bind a data source in *, I always report System.InvalidCastException: the specified transformation is invalid, no matter using the automatically generated column of Gridview or the manual column added by Reapter, there is a problem. * I found that the generated result set contains exceptions, that is, when taking the result set, you should use the following words carefully:
IPid = q.Field ("IPid"), IPFrom = q.Field ("IPFrom"), IPTo = q.Field ("IPTo"), IPCity = q.Field ("IPCity"), IPToNumber = q.Field ("IPToNumber"), IPFromNumber = q.Field ("IPFromNumber")
I later tried another way to write it:
IPid = Q ["IPid"] .ToString (), IPFrom = Q ["IPFrom"] .ToString (), IPTo = Q ["IPTo"] .ToString (), IPLocation = Q ["IPLocation"] .ToString (), IPCity = Q ["IPCity"] .ToString (), IPToNumber = Q ["IPToNumber"] .ToString (), IPFromNumber = Q ["IPFromNumber"] .ToString ()
At the beginning, I still reported System.InvalidCastException: the specified conversion is invalid. I debugged for some time, but there was still a problem. I wondered if it was the problem of data binding control. Later, I replaced the original Gridview auto-generated column with a manual input column:
Code
ID IPFrom IPTo IPLocation City IPToNumber IPFromNumber
Later, the problem was solved, and now I don't know the cause of the problem, why not support automatic generation of columns (waiting for the master to help solve it)?
Now that you know what the problem is, you can freely process the data in DataTable, such as the following simple example:
Code
Public static IEnumerable getEnumerable () {DataTable dt = getDatatable () Try {var query = from q in dt.AsEnumerable () orderby long.Parse (Q ["IPid"] .ToString () descending where q ["IPid"] .ToString () = "345058" select new {IPid = Q ["IPid"] .ToString (), IPFrom = Q ["IPFrom"] .ToString (), IPTo = Q ["IPTo"] .ToString (), IPLocation = Q ["IPLocation"] .ToString () IPCity = Q ["IPCity"] .ToString (), IPToNumber = Q ["IPToNumber"] .ToString (), IPFromNumber = Q ["IPFromNumber"] .ToString ()} Return query; / / List list = new List (); / / foreach (var q in query) / / {/ / IPInfo model = new IPInfo (); / / model.IPCity = q.IPCITY; / / model.IPFrom = q.IPFromNumber; / / model.IPFromNumber = q.IPFromNumber; / / model.IPid = long.Parse (q.IPid); / / model.IPLocation = q.IPLocation; / / model.IPTo = q.IPTo / / model.IPToNumber = q.IPToNumber; / / list.Add (model); / /} / / return list;} catch {return null }} Thank you for your reading, the above is the content of "how to solve the specified conversion invalid problem in LINQ operation DataTable". After the study of this article, I believe you have a deeper understanding of how to solve the specified conversion invalid problem in LINQ operation DataTable, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.