Tuesday, December 27, 2011

SQL to ORDER BY datetime Field by date

It's tricky to order by a datetime field by date because the GROUP BY clause attempts to group by seconds instead of days. My solution is:

SELECT
distinct Convert(varchar(10),Tasks.DateCreated,101) As Date,
Count(Convert(varchar(10),Tasks.DateCreated,101)) As DateCount
FROM Tasks
GROUP BY Convert(varchar(10),Tasks.DateCreated,101)

Wednesday, June 22, 2011

Output a DataTable in Random Order - VB.NET

To change the order of a DataTable to random, you need to change the DataTable to a DataView, add a column to the DataView, populate the fields of that column with random numbers, sort the DataView by that column, and then change the DataView back into a DataTable. The good news is this can be done in just a couple lines of code.


Dim myDataTable As DataTable
myDataTable = Whatever your data table is
myDataTable.Columns.Add(New DataColumn("RandNum", GetType(Integer)))
Dim i as Integer
Dim rndNum as New Random()
For i = 0 to myDataTable.Rows.Count - 1
myDataTable.Rows(i)("RandNum") = rndNum.Next(10000)
Next i
Dim myDataView as DataView = myDataTable.DefaultView
myDataView.Sort = "RandNum"
myDataTable = myDataView.ToTable()

Monday, March 14, 2011

Microsoft Expression Locks Up When Saving Page

If Microsoft Expression locks up, freezes, or crashes when you are trying to save an .aspx .master or other type of page, you are not alone.

Fix:
In Expression, Click --> Tools --> Application Options --> Configure Editors.
For each file extension, click New Editor --> Open as XML. Move the XML editor to the top so it says (default).

Hope this helps

Monday, January 17, 2011

Outputting Tableless HTML Navigation with ASP>NET

If you are reading this, you are probably desperately trying to find a way to implement site navigation in an unordered list. You've probably also wasted several hours on the internet learning the basics of the DataList and DataTable controls built into ASP.NET; only to learn those two controls are contrived in such a way as to only output html in a table based format.

The solution is to use an asp:repeater. Here is a really well written article describing what I agree is the best method for outputting site navigation in an ordered list format.
  1. Output your data to an xml sitemap
  2. Display the sitemap on the page as an unordered list using a Repeater .