?
Solved

ASP.Net  datatable to xml

Posted on 2009-05-07
7
Medium Priority
?
360 Views
Last Modified: 2013-12-17
I keep getting an error

System.NullReferenceException: Object reference not set to an instance of an object.
   at WebService.PropertyList() in c:\Users\Amac\Amac WebIT\WebProjects\AmacCMS\App_Code\WebService.cs:line 52

wich is the return line.

Can any one help as to what i'm doing wrong.

i am looking to get the results from a table adaptor return as an xml string;

[WebMethod]
    public string PropertyList()
    {
        HotelsDataSetTableAdapters.hotelsTableAdapter hotelAdaptor = new HotelsDataSetTableAdapters.hotelsTableAdapter();
        HotelsDataSet.hotelsDataTable hotels = new HotelsDataSet.hotelsDataTable();
        hotelAdaptor.FillAllHotels(hotels);
 
        return hotels.DataSet.GetXml();
 
    }

Open in new window

0
Comment
Question by:amacleod1983
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 
LVL 20

Expert Comment

by:informaniac
ID: 24325272
That's true coz Hotels.DataSet will give u null. It is not inside a dataset.

U'll have to declare a dataset and set the Table[0] of the dataset.

Then u can render the dataset to xml
0
 
LVL 3

Author Comment

by:amacleod1983
ID: 24325329
could you possible supply some sample code?
0
 
LVL 20

Expert Comment

by:informaniac
ID: 24325424
The problem is I don't know what is inside

HotelsDataSetTableAdapters

and HotelsDataSet

But this is my guess...

HotelsDataSet dsHotels = new HotelsDataSet();

hotelAdaptor.Fill(dsHotels,"hotels");

return dsHotels.GetXml();
0
NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

 
LVL 3

Author Comment

by:amacleod1983
ID: 24325529
What would you like to know?
Capture.JPG
0
 
LVL 3

Accepted Solution

by:
amacleod1983 earned 0 total points
ID: 24326883
got it working with this

but there must be a better way
HotelsDataSetTableAdapters.hotelsTableAdapter hotelAdaptor = new HotelsDataSetTableAdapters.hotelsTableAdapter();
        HotelsDataSet.hotelsDataTable hotels = hotelAdaptor.GetAllHotels();
        StringWriter sw = new StringWriter();
        hotels.WriteXml(sw);
        return sw.ToString();

Open in new window

0
 
LVL 20

Expert Comment

by:informaniac
ID: 24327481
That would be very much fine...

HotelsDataSet what is this?
0
 
LVL 20

Expert Comment

by:informaniac
ID: 24327517
Oh sorry.. That's the dataset.....
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Suggested Courses

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question