2009-08-24 10 views
0

日付付きのユーザー入力に基づいてXMLファイルからデータを取得したいと思います。私は、xmlファイルの日付とユーザーの入力日付を比較し、xmlファイルの日付よりも大きい場合は、それを取得する必要があります。私のlinqクエリは、このような事前の感謝のように見えます。linqからxmlへの日付の操作

XDocument xmlDoc = XDocument.Load(Server.MapPath("xml/data1.xml")); 

var hotels = from hotel in xmlDoc.Descendants("Table") 
      where Double.Parse(pplTextBox.Text) <= Double.Parse(hotel.Element("NO_OF_PEOPLE").Value) && 
      DateTime.Parse(DateTextFrom.Text) > DateTime.Parse(hotel.Element("DATE_TO").Value) 
      select new 
      { 
       RoomCost = hotel.Element("ROOM_COST").Value, 
       RoomType = hotel.Element("ROOM_TYPE").Value, 
       HotelName = hotel.Element("HOTEL_NAME").Value, 
       NoOfPeople = hotel.Element("NO_OF_PEOPLE").Value, 
       Smoking = hotel.Element("SMOKING").Value, 
       Restaurant = hotel.Element("RESTAURANT").Value, 
       //Location = hotel.Element("HOTEL_AREA").Value, 
       //AvailableDate = hotel.Element("DATE_TO").Value 
      }; 

    GridView1.DataSource = hotels.ToList(); 
    GridView1.DataBind(); 
+0

はい - 問題は何ですか?すでにXLINQクエリでDateをチェックしているようです。それからあなたの質問は何ですか? –

+0

ユーザエンドから日付を選択したとき、およびチェックのためにチェックの空きが押されたときにエラーが発生しました。日時解析エラーが発生します。文字列が有効なDateTimeとして認識されませんでした。 – user161314

+0

ユーザーは何を入力しますか?何の文字列ですか? Linq-To-XMLとはまったく関係のない文字列からDateTimeへの変換の問題はおそらく実際は....... –

答えて

0

をお使いいただけますか?

AvailableDate = (hotel.Element("DATE_TO").Value > inputDate) ? 
        hotel.Element("DATE_TO").Value : inputDate 
+0

AvailableDateで動作しない場合、追加する必要がある参照はありますか?前もって感謝します。 – user161314