views:

167

answers:

2

I have a table that looks like this:

ID / Description / textValue / dateValue / timeValue / Type
1  / FRRSD       / NULL      / 2010-04-16 00:00:00.000 / NULL / classdates

Now I've got a LINQ command to pull only the rows where the type is classdates from this table:

 Dim dbGetRegisterDates As New dcConfigDataContext
 Dim getDates = (From p In dbGetRegisterDates.webConfigOptions _
                Where p.Type = "classdates" _
                Select p)

I now want to display the data in five different labels like so:

lblClass1.Text = "Your class is from " & getDates.Description("FRRSD").dateValue & "to " & getDates.Description("FRRCD").dateValue

lblClass2.Text = "Your class is from " & getDates.Description("SORSD").dateValue & "to " & getDates.Description("SORCD").dateValue

Basically, I want to pull a row based on the description column value and then return the datevalue column value from that same row.

+1  A: 

This would work for you:

lblClass1.Text = From c in getDates Where Description = "FRRCD"
         Select string.Format("Your class is from {0} to {0}", c.dateValue)

lblClass2.Text = From c in getDates Where Description = "SORCD"
         Select string.Format("Your class is from {0} to {0}", c.dateValue)

I suspect though that what you really want is to create a note for each record you find. More like:

Dim sb = New StringBuilder()
For each c in getDates
    sb.Append(string.Format("<p><b>{0}</b>:  Your class is from {1} to {1}.</p>" _
        , c.Description, c.dateValue)
Next
classNotes = sb.toString()

And then in your page you'd put <% = classNotes %>

Patrick Karcher
+1  A: 

I don't know VB.NET syntax very well, so I'll write it in C#, but you could create a Dictionary of descriptions to dates.

var res = (from p dbGetRegisterDates.webConfigOptions
           where p.Type == "classdates"
           select new 
            {
               p.Description,
               p.dateValue
            }).ToDictionary(x=>x.Description, x=>x.dateValue);

then you can do

lblClass1.Text = string.Format("Your class is from {0} to {1}", res["FRRSD"], res["FRRCD"])

You'll probably want to do some checking that they exist too. Also, if the Description isn't unique in the results, you'll get an exception

Mike