So I am building some XML using a XmlWriter and a DataSet but when it comes time to loop through each DataRow in the DataSet I can’t figure out how do reference like ‘userid’ and such that come back from the stored procedure. In page code I see them doing it as Eval('userid') or whatever which I am using the same stored procedure, but I am using it in an ASHX now… see the ‘WHAT GOES HERE??’ in the code below…
DataSet getData; getData = SqlHelper.ExecuteDataset(ConfigurationManager.ConnectionStrings['connstr'].ConnectionString, CommandType.StoredProcedure, 'Course_NewReportGet_Get_Sav', objPAra) //COUNT NUMBER OF RESULTS FOR COUNT ATTRIBUTE (must add!) XmlWriterSettings settings = new XmlWriterSettings(); settings.Indent = true; settings.IndentChars = (' '); using(XmlWriter writer = XmlWriter.Create('data.xml', settings)) { writer.WriteStartElement('changes'); writer.WriteAttributeString('clientname', foundCompany.CompanyName); writer.WriteAttributeString('clientid', foundCompany.Abbreviation); //writer... INSERT COUNT ATTRIBUTE foreach(DataRow dr in getData.Tables) { writer.WriteStartElement('change'); writer.WriteStartElement('user'); writer.WriteAttributeString('userid', dr... WHAT GOES HERE??; } writer.WriteEndElement(); }
First off, your foreach is wrong. You need to loop over
getData.Tables[0].Rows. If there’s more than 1 table, you need to loop over getData.Tables.But, the answer is it’s an indexed property. So,
dr['userId']will get you the value.