Solved

ASP.Net  datatable to xml

Posted on 2009-05-07
7
349 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
Quiz: What Do These Organizations Have In Common?

Hint: Their teams ended up taking quizzes, too.

 
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

726 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