Posts

Eliminating Duplicates in SQL

Analyzing Duplicates My Friend David Penton wrote this article like a million years ago and being too lazy to actually commit the logic to memory - when I have duplicates I just go find the article.  Had a bit of an issue today - so when I finally found it, I decided to post it here so that I at least will know where it is - I would abbreviate it but someone might find it more valuable in its entirety as written by the talented Mr. Penton. 15 Seconds : Advanced SQL Techniques - Part 1: Analyzing Duplicate Records David Penton  10/09 / 2001 (Right - 2001 !! Does that date us or what!) This article offers an analysis of Structured Query Language (SQL) and presents techniques that can be used in building SQL statements. People tend to think of SQL as a programming language, but in reality, SQL is a Set language. One could say SQL is Set Theory or Relational Algebra; these terms are interchangeable. Some people think of this in terms of Venn diagrams or DeMorgan's Law. A...

Removing Duplicates from List Collection

Sounds really simple to pull duplicates out of a list ... MS handled this with a function in VS 3.5 but in earlier versions we had to come up with our own solution.   Dim i As Integer Dim lastapprover As String = String .Empty Dim iIndex As Integer iIndex = bulletApprovers.Items.Count For i = 0 To bulletApprovers.Items.Count - 1 While iIndex > 0           If bulletApprovers.Items(i).Text = lastapprover Then                lastapprover = bulletApprovers.Items(iIndex).Text                bulletApprovers.Items.RemoveAt(iIndex) Else               lastapprover = bulletApprovers.Items(iIndex - 1).Text End If                  iIndex = iIndex - 1 End While Next

Generic Lists to Datasets

Easy way to push a Generic List into a Dataset ** Note 'tasks' is the name of my generic list class Public Function ConvertGenericsListToDataSet( ByVal listvalue As tasks()) As DataSet Dim sb As New StringBuilder() Dim xmlSerializer As New XmlSerializer( GetType (tasks())) Dim sw As New StringWriter(sb) xmlSerializer.Serialize(sw, listvalue) Dim stream As New StringReader(sb.ToString()) Dim ds As New DataSet() ds.ReadXml(stream) Return ds End Function

Sorting Ascending and Descending

Toggling the direction of your datagrid sort is easy using a session to remember which direction you sorted last.   You will want to declare an empty string in the top of your page       Dim SortField As String Then on your sort command add this logic - Example of entire command Private Sub dgTaskExceptions_SortCommand( ByVal source As Object , ByVal e As System.Web.UI.WebControls.DataGridSortCommandEventArgs) Handles dgTaskExceptions.SortCommand     SortField = e.SortExpression If Session( "toggle" ) = True Then SortField += " DESC" Session( "toggle" ) = False Else SortField += " Asc" Session( "toggle" ) = True End If Dim orderstring As String = SortField 'REBIND dgTaskExceptions.DataSource = POTracking_Data.tracking.getSampleTasks(orderstring) dgTaskExceptions.DataBind() End Sub   In my datalayer I add this logic to my query and pass in an OPTIONAL value Dim orderbyString As String = String .Empt...

BIND AD to DataGrid

To bind the Active Directory to a datagrid I have built two functions. The first one is called either on pageload or button click or whenever you want it to happen: (Watch for wrapping) Private Function CheckAD() Dim objRootDSE = GetObject( ldap://RootDSE/ ) Dim adPath As String = "LDAP://" & Mid(objRootDSE.Get("DefaultNamingContext"), InStr(objRootDSE.Get("DefaultNamingContext"), "DC=") + 3, InStr(objRootDSE.Get("DefaultNamingContext"), "," ) - 1 - 3) Dim adAuth As LDAPAuthenticate = New LDAPAuthenticate(adPath) dgLdap.DataSource = LDAPAuthenticate.LoadADList(adPath) dgLdap.DataBind() End Function The second one actually connects to the Active Directory and returns a list of the searched properties: Public Shared Function LoadADList(ByVal pathsent As String) As List(Of LDAPAuthenticate) Dim result As SearchResultCollection = Nothing Dim entry As DirectoryEntry = New DirectoryEntry(pathsent, "testuser", " ...

Easy Nested Datagrid

Nested Grid Example ASPX Page <asp:datagrid id ="dgBids" onItemCommand ="commandDGBid" headerStyle-CssClass ="tdheaders" cellpadding ="5" runat ="server" autogeneratecolumns ="false"> < columns > < asp : BoundColumn dataField ="company" headertext ="Company"></ asp : BoundColumn > < asp : BoundColumn dataField ="bidID" visible ="false"></ asp : BoundColumn > < asp : ButtonColumn buttonType ="LinkButton" dataTextField ="bidid" CommandName ="bid" headertext ="Bid"></ asp : ButtonColumn > < asp : BoundColumn dataField ="seasondesc" headertext ="Season"></ asp : BoundColumn > < asp : BoundColumn dataField ="style" headertext ="Style"></ asp : BoundColumn > < asp : BoundColumn dataField ="styledescription"...

No Query Strings Needed

.NET allows you to reference most anything from one page to any page. An example: Page1.aspx Public Shared MyVariableThatIWant_ToPass as string = "secret information" OnAnyOtherPage. aspx Dim TheSecretFromPage1 as string TheSecretFromPage1 = MyProject.Page1. MyVariableThatIW_antToPass