Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

ASP.Net  datatable to xml

Posted on 2009-05-07
7
Medium Priority
?
368 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
Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

 
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

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

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

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…

618 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