Locations of visitors to this page


Onteora Software - May 2006

Onteora Software

Ken Tucker's Blog

About the author

Author Name is someone.
E-mail me Send mail

Recent posts

Recent comments

Disclaimer

The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

© Copyright 2008

Find Duplicate Records in a Datatable

Find Duplicate Records in a Datatable



I was asked how to find duplicate records in a datatable, I used a dataview to sort my records. I used the sorted list to check the next record for a duplicate record. The duplicate will be deleted.



Imports System.Security.Cryptography

Public Class Form1
    Dim dt As New DataTable

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        dt.Columns.Add("Name")
        dt.Columns.Add("Number", GetType(Integer))

        For x As Integer = 0 To 200
            Select Case x Mod 3
                Case 0
                    dt.LoadDataRow(New Object() {"Ken", TrueRandom.Rand(100)}, True)
                Case 1
                    dt.LoadDataRow(New Object() {"Kelly", TrueRandom.Rand(100)}, True)
                Case 2
                    dt.LoadDataRow(New Object() {"Bill", TrueRandom.Rand(100)}, True)
            End Select
        Next

        DataGridView1.DataSource = dt
        FindDups(dt)
    End Sub

    Public Sub FindDups(ByVal dt As DataTable)
        Dim dv As New DataView(dt)
        dv.Sort = "Number, Name"
        For x As Integer = 0 To dv.Count - 2
            Dim drv As DataRowView = dv.Item(x)
            Dim drvNext As DataRowView = dv.Item(x + 1)
            If drv.Item("Name").ToString = drvNext.Item("Name").ToString AndAlso drv.Item("Number").ToString = drvNext.Item("Number").ToString Then
                drv.Delete()
            End If
        Next
    End Sub
End Class


Public Class TrueRandom
    Public Shared Function Rand(ByVal MaxNum As Integer) As Integer
        Dim rnd(20) As Byte
        Dim num As Long

        Dim generator As New RNGCryptoServiceProvider

        generator.GetBytes(rnd)
        For x As Integer = 0 To 20
            num += CInt(rnd(x))
        Next x
        Return CInt(num Mod MaxNum)
    End Function

End Class

 

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Categories: Ado.Net
Posted by Ken Tucker on Monday, May 22, 2006 10:12 PM
Permalink | Comments (0) | Post RSSRSS comment feed

Active Directory users

Active Directory users



There is no way to get a users password from an active directory. One of the DirectoryEntry constructor overloads allows you to specify the username and password. To see if the user name and password are correct try and create a directoryEntry object with the given username and password. If the password username combination are incorrect you will get an exception. Here is a sample function to authenicate a user.



 Public Function Authenicate(ByVal username As String, ByVal password As String) As Boolean
        Dim isValid As Boolean = False
        Try
            Dim de As New DirectoryServices.DirectoryEntry("LDAP://YourActiveDirectoryName", username, password, _
                    DirectoryServices.AuthenticationTypes.Secure Or _
                    DirectoryServices.AuthenticationTypes.Sealing Or _
                    DirectoryServices.AuthenticationTypes.Signing)
            de.RefreshCache()
            isValid = True
        Catch
        End Try
        Return isValid
    End Function

Currently rated 4.0 by 1 people

  • Currently 4/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Categories: VB
Posted by Ken Tucker on Sunday, May 21, 2006 1:12 AM
Permalink | Comments (0) | Post RSSRSS comment feed

DXCore

DXCore



Developers express has a free product DX Core. It is a framework to develop add ins for visual studio. With it you can paint on the ide, work with the text, etc.


I answer alot of questions in the newsgroups and forums. From time to time I copy code from the ide and when it pasted it looses the format. To overcome this limitation I usually paste the text in notepad. I then recopy the text and paste it in the question I am answering to preseve the format.


Today I used the dxcore to add the copy as text to context menu when you right click on selected code. Step one download and install the DXCore. Note the dx core does not work with the express editions of visual studio.


Step 2 from the DevExpress menu added to visual studio select New Plug in. This will create a project for the addin.


Step 3 Drag a Action on to the designer from the toolbox. Set it action name, button text, and desciption to Copy as Text. Set the CommonMenu to EditorContext. Double Click on the action and add this code to the Action_Execute Event.

    Private Sub Action1_Execute(ByVal ea As DevExpress.CodeRush.Core.ExecuteEventArgs) Handles Action1.Execute
        Dim template As String = CodeRush.Selection.Text

        Clipboard.SetDataObject(template)

    End Sub

Run this from the ide. It will open up another instance of the ide. Open a project and select some code and right click on it. You will see the copy as text in the menu, Boy does dev express make it easy.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Categories: General | DXCore
Posted by Ken Tucker on Monday, May 15, 2006 10:12 PM
Permalink | Comments (0) | Post RSSRSS comment feed

Atlas Tool Kit

Atlas Tool Kit



The atlas tool kit is truely awsome. I see there is an error in collapsiblepanelextender documentation. The sample code on the webpage shows the expanddirection as height when the valid values are horizontal and vertical. It also shows openedsize instead of expandedsize.



             <atlasToolkit:CollapsiblePanelExtender ID="cpe" runat="Server">
                <atlasToolkit:CollapsiblePanelProperties ExpandedSize="200" TargetControlID="pnlRss"
                    ExpandControlID="LinkButton1" CollapseControlID="LinkButton1" Collapsed="True"
                    TextLabelID="LinkButton1" CollapsedText="Show Details..." ExpandedText="Hide Details..."
                    SuppressPostBack="true" />
           </atlasToolkit:CollapsiblePanelExtender>
           <asp:Label ID="lblRss" Text="Whats New in VB-Tips" runat="server"></asp:Label>
<asp:LinkButton ID="LinkButton1" runat="server" Text="Show Details..">
</asp:LinkButton>
          
     <asp:Panel ID="pnlRss" runat="server" Width="100%" ScrollBars="Vertical">
                <asp:DataList ID="DataList1" runat="server" BackColor="White" BorderColor="#E7E7FF"
                    BorderStyle="None" BorderWidth="1px" CellPadding="3" DataSourceID="RssDataSource1"
                    GridLines="Horizontal">
                    <FooterStyle BackColor="#B5C7DE" ForeColor="#4A3C8C" />
                    <SelectedItemStyle BackColor="#738A9C" Font-Bold="True" ForeColor="#F7F7F7" />
                    <ItemTemplate>
                         <asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl='<%# Eval("link") %>'
                            Text='<%# Eval("title") %>'></asp:HyperLink><br />
                        <asp:Label ID="descriptionLabel" runat="server" Text='<%# Eval("description") %>'></asp:Label><br />
                        <br />
                        pubDate:
                        <asp:Label ID="pubDateLabel" runat="server" Text='<%# Eval("pubDate") %>'></asp:Label><br />
                        <br />
                    </ItemTemplate>
                    <AlternatingItemStyle BackColor="#F7F7F7" />
                    <ItemStyle BackColor="#E7E7FF" ForeColor="#4A3C8C" />
                    <HeaderStyle BackColor="#4A3C8C" Font-Bold="True" ForeColor="#F7F7F7" />
                </asp:DataList><cc1:RssDataSource ID="RssDataSource1" runat="server" MaxItems="0"
                    Url="http://www.vb-tips.com/newsfeed.aspx">
                </cc1:RssDataSource>
            </asp:Panel>
           <atlas:ScriptManager ID="s1" EnablePartialRendering="true" runat="server">
            </atlas:ScriptManager>

 

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Categories: Ajax
Posted by Ken Tucker on Sunday, May 07, 2006 10:12 PM
Permalink | Comments (0) | Post RSSRSS comment feed