Friday, June 25, 2010

Remove duplicate characters in a string in VB

A simple code to remove duplicate characters in a string. Is there any better solution?

Public Function DuplicateTrim(ByVal Value As String) As String

Dim ASCII As Integer
Dim Temp As String

For ASCII = 33 To 126
' Get first location of the letter
If InStr(1, Value, Chr(ASCII), CompareMethod.Binary) > 0 Then
' letter exists
Temp &= Chr(ASCII)
' Remove all characters matching in original
Value = Value.Replace(Chr(ASCII), "")
End If

Return Temp

End Function

How to show running serial no. in SQL SERVER Select Statement

I am working on a project where the SQL is generated at runtime depending on users selection and i am show the records from database in a Gridview control.
I am to show Running Serial Nos. as Serial No. column as the first column in the grid.

The solution to this requirement is to to genarate SR.No column in SQL as follows

SELECT ROW_NUMBER() OVER (ORDER BY ColumnName1) As Sr_No, ColumnName1, ColumnName2 FROM TableName