Guys I think I'm somewhere near with the below but also way off the mark still, I'm trying to fetch an xml then display the results into a datagrid using the below Webrequest, it doesn't throw an error but then It doesn't display either, am I missing the xml read part or am I overlooking something simple?
HttpWebRequest request = WebRequest.Create(http://myurl/xml) as HttpWebRequest;
// Get response
using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
{
// Load data into a dataset
DataSet dsWeather = new DataSet();
dsWeather.ReadXml(response.GetResponseStream());
// display dataset information
dataGridView1.DataSource = dsWeather;
}
Sam HobbsPosted Aug 28, 2011, 10:19 AM
VulpesPosted Aug 28, 2011, 5:10 AM
mike DelvottiPosted Aug 28, 2011, 5:03 AM
Sam, it's not like that – I'm not ignoring your help I'm grateful of everybody's reply. I appreciate your help and I'm sorry if I've offended you.
Sam HobbsPosted Aug 27, 2011, 8:51 PM
Since you are asking for help from just Vulpes and ignoring my help, I will stop trying to help.
mike DelvottiPosted Aug 27, 2011, 7:58 PM
Sam, yes you are right I did use the code from one of those sites as an example, but Vulpes that tip helped with the dataGridView1.DataSource = dsWeather.Tables[0];, as it then threw an error which pointed me in the right direction (I had my url wrong ;)
Just one other quick question vulpes, now it works binding to a datagrid could I dislpay the results to say textbox1, textbox2 and so on instead of a datagrid?
Thanks guys.
Sam HobbsPosted Aug 27, 2011, 6:39 PM
I said "ReadXml returns a DataSet, not a table". For example see How To Read XML Data into a DataSet by Using Visual C# .NET; it shows use of the DataMember to specify a table name.
You probably copied sample code from one of the following two sites. If not then perhaps you are missing some useful code.
- Using Returned XML with C# - Yahoo! Developer Network
- Sommers tech journal: Using Returned XML with C#
That sample code is a console program that shows the tables in the data set created when a XML file is read. You can use that sample code to test the part of your code that gets the XML file.VulpesPosted Aug 27, 2011, 6:22 PM
As Sam intimated earlier, I'd try binding to the first DataTable rather than the DataSet as a whole:
dataGridView1.DataSource = dsWeather.Tables[0];
mike DelvottiPosted Aug 27, 2011, 5:49 PM
the xml i'm contacting sits on a web server, i send the url with my credentials then bring back the xml, i'm fairly sure it gets to the xml it just won't fetch it back and read it into my datagridview?
VulpesPosted Aug 27, 2011, 5:26 PM
mike DelvottiPosted Aug 27, 2011, 4:18 PM
Sam HobbsPosted Aug 27, 2011, 1:25 PM
Second note that ReadXml returns a DataSet, not a table. You need to specify which table in the data set to use.
The sample that you copied probably shows that. It shows the data that was read, correct? Try using the sample as-is to see what tables are returned.
mike DelvottiPosted Aug 27, 2011, 12:16 PM
It doesn't populate the datagrid with any info but I'm sure it's contacting the remote xml file.
Suthish NairPosted Aug 27, 2011, 11:54 AM
Did the url returns required output?
Put a break point on dsWeather and check it returns data table with records.
Did your DataGridview have same structure as data table?