I have an application which calls a web service. For this I am using LINQ.
What I want to do is the value of 'Caption' come from an XML file in which I pass as a parameter.
When doing the debug I see that the parameter passes well, but it returns null.
What am I doing wrong?
Here is my code:
This is the XML file:
<root>
<dataSourceCaption>Users</dataSourceCaption>
</root>
This is the code:
int count = xml.GetElementsByTagName("dataSourceCaption").Count;
for (int i = 0; i < count; ++i)
{
dataSourceCaption.Add(xml.GetElementsByTagName("dataSourceCaption")[i].InnerText);
}
var ds = etDataSourceMappingTable();
foreach (DataTable dst in ds.Tables)
{
foreach (DataRow dr in dst.Rows)
{
//var DataSourceId = dr["SourceID"].ToString();
var DataSourceId = ds.Tables["Table"]
//.Select("Caption = 'TeachersTests'") // Find rows with Caption
.Select("Caption = '" + dataSourceCaption.ToString() + "'") // Find rows with Caption
.Select(r => r["SourceID"]) // Project to the value of SourceId
.Where(s => s != DBNull.Value) // Filter DBNull (might occur when the SourceID cell is missing
.Select(s => s.ToString()) // Project to string value
.FirstOrDefault();
SourceID = DataSourceId;
}
}
return SourceID;
This is the schema of the web service I'm calling:
<xs:schema id="NewDataSet" xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xs:element name="NewDataSet" msdata:IsDataSet="true" msdata:UseCurrentLocale="true">
<xs:complexType>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element name="Table">
<xs:complexType>
<xs:sequence>
<xs:element name="SourceID" type="xs:string" minOccurs="0"/>
<xs:element name="Caption" type="xs:string" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:schema>