.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links


Posted By:      Posted Date: October 22, 2010    Points: 0   Category :ASP.Net

        XDocument doc = XDocument.Load("http://localhost:49545/Default/XMLFile2.xml");

        var data = from c in doc.Descendants(XName.Get("tecajnica")).Descendants()
                   //where c.Attribute("oznaka").Value == "USD"
                   where c.Attribute("oznaka").Value == "USD" && c.Attribute("sifra").Value == "840"
                   select new

                       oznaka = c.Attribute("oznaka").Value,
                       sifra = c.Attribute("sifra").Value,

        GridView1.DataSource = data;

<bookstore xmlns:bk="urn:samples">
  <tecajnica datum="2010-10-21">
    <tecaj oznaka="USD" sifra="840">1.4016</tecaj>
    <tecaj oznaka="JPY" sifra="392">113.65</tecaj>
    <tecaj oznaka="BGN" sifra="975">1.9558</tecaj>
    <tecaj oznaka="CZK" sifra="203">24.540</tecaj>
    <tecaj oznaka="DKK" sifra="208">7.4584</tecaj>
    <tecaj oznaka="EEK" sifra="233">15.6466</tecaj

View Complete Post

More Related Resource Links

Converting Date to String and Formating it Linq to SQL

Hello I have problem in converting date to string I am using cstr(p.tripstart) , which is returning Date as 12 Aug 2010 12:AM   I need to make formating   This is my code : Dim db As New TripsLinqDataContext Dim listtrips = (From p In db.Trips _ Group Join c In db.Countries On p.TripCountryID Equals c.TripCountryID Into countrylist = Group _ Select New With {.Tripdetails = p.TripDescription + " - " + p.TripCityList + " - " + CStr(p.tripstart) + " - " + CStr(p.TripDays), _ .Tripid = p.TripID}).ToList tripboxlist.DataSource = listtrips tripboxlist.DataTextField = "Tripdetails" tripboxlist.DataValueField = "Tripid" tripboxlist.DataBind()     Regards  

Compare Date in LINQ

Dear all, How to do in LINQ?? And below is correct or not if put string.format in LINQ??   Datetime updatedDate=DateTime.Now; string upddate=string.format("yyyy-MM-dd", updatedDate); var result=( from p in W_Order                   where string.format("yyyy-MM-dd", p.orderdate) == upddate                    select new order {                       .........                        }).toList();            

How to retrive a date time value from TimeStamp column using Linq?


I have a Timestamp column in my Table. I want to read the date time value and display in UI.

In Linq the Timestamp column is represented as System.Data.Linq.Binary.

I dont know how to retirve date time value in "MM-dd-YYYY" format from this Linq.Binary


- Why I am using Timestamp?.

I want to perform some operations based on the last modified date time of the particular row. Since I am using TimeStamp column in my Table as version column, It will contain the last modified date details, So i want to read the date time value from this time stamp column to do some other operations.



Find the nearest date before Saturday, Sunday and holidays with Linq


 var tecaji = (from xml in doc.Descendants(slazhnmaespace + "tecajnica")
                      where xml.Attribute("datum").Value == "2010-10-158"
                      select xml).Elements().Where(a => a.Attribute("oznaka").Value.Equals("TRY")).Select(n => n.Value).SingleOrDefault();

I have dates that are not in the XML file, but value still has to show.

In the table there is no value for the date of 23.10.2010, 24.20.2010. How do you show value for the date 10/22/2010?

Finding the appropriate date, which is najbluzjemu to that in the table.

In this XML table is not displayed dates (Saturday - Sunday).

Therefore, to find the nearest date before Saturday and Sunday.

If it is Saturday, the date "02.10.2010" shall be the date of "01/10/2010.

How do I get to that solution?


How to get the Nearest date with Linq


            var querysnajblizjidatum = (from xml in doc.Descendants(slazhnmaespace + "tecajnica")
                          where xml.Attribute("datum").Value == datumstroska.ToString("yyyy'-'MM'-'dd")
                                      //  where xml.Attribute("Datum").Value.Equals("10-21-2010") //< najblizjidatum 
                                        where (xml >= xml.Attribute("Datum").Value >= "10.5.2010")  
                          select xml).Elements().Where(a => a.Attribute("oznaka").Value.Equals(ddlValutaStroska.SelectedValue.Substring(0, 3))).Select(n => n.Value).SingleOrDefault();

How to get the Nearest date? My code does work.


If the date of 16.10.2010, I want print, 15.10.2010

If the date of 21.10.2010, I want print, 18.10.2010

If the date of 19.11.2010, I want print, 8.11.2010



Nearest date with Linq



If I choose the date 10.02.2010 and there is none, I want to find the earliest date.


Find a date that does not exist, it is 03.10.2010.
Given that the date in the table does not exist, I want to find 1.10.2010.

If I want to find 20.10.2010 and it does not find, print 15.10.2010.


How do I find nearest date with LINQ, if I can not find?

Playing with Linq grouping: GroupByMany?

One of its features is grouping. Many people understand grouping like it is defined in Sql. Linq is implementing grouping quite the same way. Let's discover this syntax and how to make consecutive groups easier.

LINQ : Implementing IN and NOT IN

I got tried of typing

var result = from s in source
where items.Contains(s)
select s;and so I implemented the IN and NOT IN methods as extension methods:

101 LINQ Samples Tutorials

101 LINQ Example with sample code snippets....This sample prints each element of an input integer array whose value is less than 5. The sample uses a query expression to create a new sequence of integers and then iterates over each element in the sequence, printing its value

Using a CompareValidator to check input is a valid date

The CompareValidator can do more than just compare two controls. You can also compare it against several of the main .net data types such as Date, Integer, Double and Currency.

To do this you would set Operator="DataTypeCheck" and instead of setting the ControlToCompare or ValueToCompare attributes as you normally would you use the Type="Date" (or any of the data types I have listed above).

Linq: how to share parameters between lambda expressions ?

When using Linq to objects, you will quickly feel the need to pass some parameters from a method to another but it's not so easy because each Linq method is not calling the following one. In a Linq sequence, each method is using the result computed by the previous one. So, local contexts are not visible from one method to another.
The compiler is using two technical different ways to let parameters go out of a method.

Linq to Sql CompiledQuery container

Ok now let's go. Here is just a little trick but with some interesting patterns that could be useful in some other contexts not connected to Linq to Sql.

When using Linq expressions, like with Linq to Sql, translating the expression into something else (sql for example) is taking time and resources. Sometimes it's negligible, sometimes not...

How To Set a Date Format In GridView Using ASP.NET 2.0

A very common desire is to set a column of a gridview to display just the month, day and year of a DateTime type. The problem is the by default, the HtmlEncode property of the boundfield attribute (
The problem is that if this field is enabled, you can not pass format information to the boundfield control. That is, if you try the following code, you will not get the desired result.

LINQ to SQL Paging using GridView in C# and ASP.NET 3.5

This tutorial will show you how we can extend the LINQ to SQL Class and create methods that will allow us to page data from a SQL database. C# version.

jQuery Date picker Implementation in ASP.NET

I've posted a wrapper ASP.NET around the jQuery.UI Datepickercontrol. This small client side calendar control is compact, looks nice and is very easy to use and I've added it some time back to my control library.

This is primarily an update for the jQuery.ui version, and so I spend a few hours or so cleaning it up which wasn't as easy as it could have been since the API has changed quite drastically from Marc's original implementation. The biggest changes have to do with the theming integration and the resulting explosion of related resources.

If you want to use this component you can check it out a sample and the code here:

What is Lambda Expressions In LINQ

A lambda expression is an anonymous function that can contain expressions and statements, and can be used to create delegates or expression tree types.

All lambda expressions use the lambda operator =>, which is read as "goes to". The left side of the lambda operator specifies the input parameters (if any) and the right side holds the expression or statement block. The lambda expression x => x * x is read "x goes to x times x." This expression can be assigned to a delegate type as follows:

How to create 3 tier application using LINQ

As you know that in 3 tier architecture there are three layers

User interface layer. (Is our Form in Windows application and .aspx page in Web application)
Data Access layer. (Which provides interface between Business logic layer and Database)
Business Logic layer.(Which stores your application logic)
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend