xml - Accessing to a dataset value using C# -
i have application calls web service getdatasourcemappingtable data structure data set
.
what trying extract value of column (users_tests) give me mandatory parameter able call web service getuser()
.
here have data set structure:
getdatatableresponse xmlns="http://tempuri.org/"> <getdatatableresult> <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>
i need call element name "caption"
, pass value users_test
(where users_test value inside table) sourceid e.g. "data1"
here code far:
var ds = proxy.getdatatable(); var datasourceid = ds.tables["table"].select("caption = 'users_test'"); userdata[] userdataid = client.getuser(ref apikey, ref message, datasourceid.tostring()); //getuserdata need sourceid e.g. data1 able used
whenever run program in datasourceid variable inside getuser()
method not being passed correctly. array 0 , 1. in 0 data1 , in 1 users_tests.
i suppose e.g. "data1"
how can value of caption give sourceid
getuser()
method?
as able have multiple captions such (select("caption = 'users_test'");
, select("caption = 'users_test1'");
, select("caption = 'users_test3'");
is possible?
thanks
datatable.select()
returns datarow[]
array, can use linq select
method project rows entry caption
. following expression gets sourceid
value corresponding caption, returns null
if not found, , throws exception on multiple matches:
var datasourceid = ds.tables["table"] .select("caption = 'users_test'") // find rows caption = 'users_test' .select(r => r["sourceid"]) // project value of sourceid .where(s => s != dbnull.value) // filter dbnull (might occur when sourceid cell missing .select(s => s.tostring()) // project string value .singleordefault(); // null if no matches, throw exception if more 1 match.
if might reasonably expect more 1 row caption = 'users_test'
, can loop through them foreach
statement:
var query = ds.tables["table"] .select("caption = 'users_test'") // find rows caption = 'users_test' .select(r => r["sourceid"]) // project value of sourceid .where(s => s != dbnull.value) // filter dbnull (might occur when sourceid cell missing .select(s => s.tostring()); // project string value foreach (var datasourceid in query) { }
prototype fiddle.
update
to select multiple captions datatable.select()
, use or
operator:
var query = ds.tables["table"] .select("caption = 'users_test' or caption = 'users_test3'") // find rows of several captions .select(r => r["sourceid"]) // project value of sourceid .where(s => s != dbnull.value) // filter dbnull (might occur when sourceid cell missing .select(s => s.tostring()); // project string value
Comments
Post a Comment