Click here to Skip to main content
15,888,351 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have an XML file consisting of an element "Settings". All the rest of the elements are getting populated in DataTable but settings.
While reading in the XML file this is the reference code i implemented.
But the breakpoint is not hitting the "Settings" case.

C#
foreach (DataRow drow in dtFilteredDeviceDefintion.Rows)
               {
                   if (drow["Section"] == null || drow["Section"] == DBNull.Value)
                       continue;

                   string sectionName = Convert.ToString(drow["Section"]).ToLower().Trim();

                   switch (sectionName)
                   {
                       case "devicedefinition":
                           if (drow["DeviceCommunication"] != null && drow["DeviceCommunication"] != DBNull.Value)
                               deviceDefinitionType.DeviceCommunication = Convert.ToInt32(drow["DeviceCommunication"].ToString());

                           if (drow["UserAuthenticationType"] != null && drow["UserAuthenticationType"] != DBNull.Value)
                               deviceDefinitionType.UserAuthentication = Convert.ToInt32(drow["UserAuthenticationType"]);
                           deviceDefinitionType.ID = Convert.ToString(drow["DeviceDefinitionID"]);
                           deviceDefinitionType.SoftwareVersion = Convert.ToString(drow["SoftwareVersion"]);
                           deviceDefinitionType.DeviceType = Convert.ToString(drow["DeviceType"]);
                           deviceDefinitionType.Model = Convert.ToString(drow["Model"]);
                           deviceDefinitionType.Manufacturer = Convert.ToString(drow["Manufacturer"]);
                           break;
                       case "settings":
                           SettingType st = new SettingType();
                           st.Name = Convert.ToString(drow["SettingName"]);
                           st.Description = Convert.ToString(drow["SettingDescription"]);
                           st.IsInitialDeviceSetting = Convert.ToString(drow["IsInitialDeviceSetting"]).ToLower() == "true" ? true : false;
                           st.ReadOnlySpecified = true;
                           st.ReadOnly = Convert.ToString(drow["IsReadOnly"]).ToLower() == "true" ? true : false;
                           st.SettingDisplayText = Convert.ToString(drow["SettingLabel"]);
                           st.ID = Convert.ToString(drow["DeviceDefinitionSettingID"]);
                           st.CategoryID = Convert.ToString(drow["DeviceDefinitionCategoryID"]);

                           if (drow["DisplayOrder"] != null && drow["DisplayOrder"] != DBNull.Value)
                           {
                               st.DisplayOrder = Convert.ToInt32(drow["DisplayOrder"]);
                           }


What can be the reasons that this single element is not being read while others are?
Posted
Comments
CHill60 5-Aug-14 2:52am    
You have "Settings" in your question but "settings" in your code. Could you have the case wrong?
Anshumaan Chaturvedi 5-Aug-14 3:07am    
Well, the case was handled already. Irrespective of what case it is,the elements are read in Datatable except Settings.
johannesnestler 5-Aug-14 7:42am    
So you VERIFIED that your sectionName variable equals "settings" but the case doesn't get called? - No I can't believe that - so check your sectionName during debug and I bet you won't see any "settings" value. More likely you have a problem before this loop executes. (initialization of rows? STRONG HINT the Name of your list variable: dtFilteredDeviceDefintion.Rows). Btw. it would improve performance and readabillity if you don't access the same cell muliple times: ... drow["Section"] - read it once to a local varialbe then do your checks (no need for the indexer looping through your columns and what not...)
CHill60 5-Aug-14 9:03am    
As in "case-sensitive"
johannesnestler 5-Aug-14 9:13am    
He is looping over an enumeration called tFilteredDeviceDefintion - so I suspect it is what it's Label says: "A filterd list with only the devicedefinition and no settings"...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900