Locations of visitors to this page


Onteora Software - February 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

USB drive insert notification

USB drive insert notification



The wmi supports events. I use the instance creation event for the Win32_LogicalDisk for the notification. Add a reference to the system.management for this sample. You need a form with a listbox for the code to work.



Imports System.Management

Public Class Form1
    Dim WithEvents w As ManagementEventWatcher
    Dim q As WqlEventQuery
    Delegate Sub LoadList()

    Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
        w.Stop()
    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Try
            q = New WqlEventQuery
            q.QueryString = "SELECT * FROM" & _
                        " __InstanceCreationEvent WITHIN 1 " & _
                        "WHERE TargetInstance isa ""Win32_LogicalDisk"""
            w = New ManagementEventWatcher(q)
            w.Start()
        Catch ex As Exception
            Trace.WriteLine(ex.ToString)
        End Try
        LoadDriveList()
    End Sub

    Private Sub LoadDriveList()
        ListBox1.Items.Clear()
        Dim moReturn As Management.ManagementObjectCollection
        Dim moSearch As Management.ManagementObjectSearcher
        Dim mo As Management.ManagementObject

        moSearch = New Management.ManagementObjectSearcher("Select * from Win32_LogicalDisk")

        moReturn = moSearch.Get
        For Each mo In moReturn
            ListBox1.Items.Add(mo("Name").ToString)
        Next

    End Sub

    Private Sub w_EventArrived(ByVal sender As Object, ByVal e As System.Management.EventArrivedEventArgs) Handles w.EventArrived
        ListBox1.Invoke(New LoadList(AddressOf LoadDriveList))
    End Sub
End Class

 

Be the first to rate this post

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

Categories: WMI
Posted by Ken Tucker on Saturday, February 25, 2006 11:12 PM
Permalink | Comments (0) | Post RSSRSS comment feed

Real Random Numbers

Real Random Numbers



The random function does not generate truely random numbers. Use the RNGCyptoServiceProvider to create them



Imports System.Security.Cryptography


Public Class Form1

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        FillList()
    End Sub

    Private Sub FillList()
        ListBox1.Items.Clear()
        For x As Integer = 0 To 20
            ListBox1.Items.Add(TrueRandom.Rand(500).ToString)
        Next
    End Sub

    Private Sub btnNewList_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNewList.Click
        FillList()
    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: Archive | VB
Posted by Ken Tucker on Wednesday, February 22, 2006 11:12 PM
Permalink | Comments (0) | Post RSSRSS comment feed

VB 2005 Complier Hotfix

VB 2005 Complier Hotfix



There was a hot fix released for the VB 2005 complier problem described here. If you are having the problems listed call PSS (Product Support Services) 800-936-4900 and tell Technical Routers that they want to be transferred to Developer Support, Visual Basic team, it would expedite the call. Ask about getting the patch for KB# 915038.


Be the first to rate this post

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

Categories: VB
Posted by Ken Tucker on Tuesday, February 21, 2006 12:42 PM
Permalink | Comments (0) | Post RSSRSS comment feed

KJM Solutions

KJM Solutions



KJM Solutions is now open for web hosting. We offer .NET Framework 1.1 and .NET Framework 2.0, ASP.NET, application hosting and web services hosting. 1 GB Disk Space divided among all services as you choose, 350GB Monthly Data Transfer, Unlimited POP3 Email Accounts, Unlimited Microsoft SQL Server 2005 Databases, Unlimited Microsoft SQL Server 2000 Databases, Unlimited FTP Accounts, Unlimited Email Forwards, Frontpage 2002 Extensions, 24/7 Email Support, Web Based Email for $35.00 per month. The first 3 months are free.

Contact Sales for more info.


Be the first to rate this post

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

Categories: Archive
Posted by Ken Tucker on Monday, February 20, 2006 12:42 PM
Permalink | Comments (0) | Post RSSRSS comment feed

Restore SQL 2005 Database

Restore SQL 2005 Database



You can use the smo restore class to restore a sql server 2005 database. SqlExpress databases must be restored from the sql express directory. This sample restores the northwind database backed up in my last blog entry. You need to add a reference to Microsoft.SQLServer.SMO for this sample to work.



Using SMO with Sql Express

Imports Microsoft.SqlServer.Management.Smo

Module Module1

    Sub Main()
        Dim svr As Server = New Server(".\SQLEXPRESS")
        Dim rst As Restore = New Restore
        Dim strPath As String = svr.Information.MasterDBPath
        strPath = strPath.Replace("\DATA", "\Backup\Nwnd.Bak")
        rst.Devices.Add(New BackupDeviceItem(strPath, DeviceType.File))
        rst.Database = "Northwind"
        rst.ReplaceDatabase = True
        Try
            rst.SqlRestore(svr)
        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try
    End Sub

End Module

Be the first to rate this post

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

Categories: Sql | VB
Posted by Ken Tucker on Friday, February 17, 2006 12:12 AM
Permalink | Comments (0) | Post RSSRSS comment feed

Backup SQL 2005 Database

Backup SQL 2005 Database



You can use the smo backup class to backup a sql server 2005 database. SqlExpress databases must be backed up to the sql express directory. You need to add a reference to Microsoft.SQLServer.SMO for this sample to work.



Using SMO with Sql Express

Imports Microsoft.SqlServer.Management.Smo

Module Module1

    Sub Main()
        Dim svr As Server = New Server(".\SQLEXPRESS")
        Dim bkp As Backup = New Backup()
        Dim strPath As String = svr.Information.MasterDBPath
        strPath = strPath.Replace("\DATA", "\Backup\Nwnd.Bak")
        bkp.Action = BackupActionType.Database
        bkp.Database = "NorthWind"
        Dim bdi As New BackupDeviceItem(strPath, DeviceType.File)
        bkp.Devices.Add(bdi)
        Try
            bkp.SqlBackup(svr)
        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try
    End Sub

End Module

Module

Be the first to rate this post

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

Categories: Sql | VB
Posted by Ken Tucker on Wednesday, February 15, 2006 11:12 PM
Permalink | Comments (0) | Post RSSRSS comment feed

Got Code?

Got Code?



Orlando .NET CodeCamp Saturday, March 25 2006

Here is a list of the topics


3D For the Rest of Us (Avalon/WPF)
7 Ways to Ajax
ASP.NET 2.0 Membership and Role Management
An In-depth look at Profiles in ASP.NET 2.0
A guide to developing Web Server Controls
Accessible Web Applications (Section 508)
Building new apps with ATLAS - Smart Client Application Development & Deployment
Customizing the Windows Forms DataGridView
Generic Database Programming with ADO.NET
DotNetNuke Chalk Talk / BOF
Developing Custom Modules the easy way with code generation and freely available tool
Introduction to the DotNetNuke portal framework (part 1)
Introduction to the DotNetNuke portal framework ( part 2)
What kind of modules can you use with DotNetNuke?
Real-world DotNetNuke skinning
Stan Schultes on DNN - Enterprise Library 2.0
Game Development in .NET (PART1)
Game Development in .NET (PART2)
Advanced Generics
Using .NET Generics
Getting Started with Real World SQL Server Integration Services
Getting Started with Virtual Earth and SQL2005 CLRs
Overview of the LINQ project
What’s New in Microsoft Solutions Framework (MSF) Version 4.0
Honey I got threaded -Multithreading in .NET
Developing N-Tier Application with C#, MSSQL 2005, and XML
Beginning Reporting Services 2005
Smart Client Application Development & Deployment
Primer for Secure Coding (Part I)
A Primer for Secure Coding (Part II)
Portal Smackdown
DotNetNuke versus Sharepoint
SOA Design Strategies: Adhering to the 4 Tenets
Service Orientation – What it REALLY Means! (chalk talk)
Getting Started with SQL Data Mining
DBA Enhancements to SQL Server 2005
Hacking SQL Server
SQL Server Management Objects
Getting the most out of SSIS
CLR Objects in Sql Server 2005
Software Factory Assembly Line
Designing the Test Driven Way
How Developers can use Virtualization to their Advantage
Getting to Know Windows Workflow Foundation
Visual Studio 2005 Debugging
Building an Office Solution using Visual Studio Tools for Office 2005
Visual Studio Team System Designers for Architects
Streamline Build Processes in Team System
Intro to Visual Studio 2005 Team Systems
Introducing Windows Communication Framework
Workflow, ASMX, and Indigo
Ensure A Seamless Upgrade Path to WCF with ASMX 2 and WSE 3
CLR and YOU
DBA’s and DEV’s Coding Up SQL 2005

email Joe Healy for more info

Be the first to rate this post

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

Categories: Camp
Posted by Ken Tucker on Wednesday, February 15, 2006 12:42 PM
Permalink | Comments (0) | Post RSSRSS comment feed

Async DataGridView fill Issue

Async DataGridView fill Issue



Here is an issue brought up by fellow MVP Jose Fuentes. When filling a data table asyncronously bound to a datagridview you will wind up with a blank line in the datagridview. To get around this issue do not set the datasource until the data table is filled.



Public Class Form1
    Dim dt As New DataTable
    Delegate Sub ReloadGrid(ByVal dt As DataTable)

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        dt.Columns.Add("Column1")
        dt.Columns.Add("Column2")
        ' comment out the next line to load grid properly
        DataGridView1.DataSource = dt
        Me.FillDALViaThread(dt, Me)
    End Sub


    Public Sub FillDALViaThread(ByRef DT As DataTable, ByVal ParentObj As System.Windows.Forms.Control)
        Dim DEL As New FillDataDelegate(AddressOf FillData)
        DEL.BeginInvoke(DT, ParentObj, New AsyncCallback(AddressOf FillDataCallBack), New Object() {DEL, DT, ParentObj})
    End Sub

    Private Function FillData(ByRef DT As DataTable, ByVal ParentObj As System.Windows.Forms.Control) As DataRow
        Dim DR As DataRow = DT.NewRow
        DR.Item("Column1") = "test" & DT.Rows.Count
        If DT.Rows.Count = 5 Then
            DataGridView1.Invoke(New ReloadGrid(AddressOf SetDataSource), DT)
            Return Nothing
        End If
        Return DR
    End Function

    Public Delegate Function InvokeMethod(ByVal obj As Object, ByVal params() As Object) As Object
    Public Delegate Function FillDataDelegate(ByRef DT As DataTable, ByVal ParentObj As System.Windows.Forms.Control) As DataRow

    Public Sub FillDataCallBack(ByVal ar As IAsyncResult)
        Dim del As FillDataDelegate = CType(CType(ar.AsyncState, Object())(0), FillDataDelegate)
        Dim ParentObj As System.Windows.Forms.Control = CType(CType(ar.AsyncState, Object())(2), System.Windows.Forms.Control)
        Dim DT As DataTable = CType(CType(ar.AsyncState, Object())(1), System.Data.DataTable)
        Dim Minfo As System.Reflection.MethodInfo

        Minfo = Me.GetMethod(DT.Rows, "Add")

        If Minfo IsNot Nothing Then
            Dim DR As Object = del.EndInvoke(DT, ar)
            If DR IsNot Nothing Then
                Trace.WriteLine("Test " & DirectCast(DR, DataRow).Item("Column1").ToString)
                If Not DT.PrimaryKey Is Nothing Then
                    If DT.PrimaryKey.Length > 0 Then
                        If IsDBNull(DR(DT.PrimaryKey(0).ColumnName)) Then
                            Return
                        End If
                    End If
                End If
                ParentObj.Invoke(New InvokeMethod(AddressOf Minfo.Invoke), New Object() {DT.Rows, New Object() {DR}})
                Me.FillDALViaThread(DT, ParentObj)
            End If
        End If

    End Sub

    Private Function GetMethod(ByVal Obj As Object, ByVal Name As String) As System.Reflection.MethodInfo
        For Each Minfo As System.Reflection.MethodInfo In Obj.GetType.GetMethods
            If Minfo.Name.ToLower.Trim = Name.ToLower.Trim Then
                Return Minfo
            End If
        Next
        Return Nothing
    End Function

    Private Sub SetDataSource(ByVal dtSource As DataTable)
        DataGridView1.DataSource = dtSource
    End Sub
End Class

Be the first to rate this post

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

Categories: DataGridView
Posted by Ken Tucker on Monday, February 13, 2006 11:12 PM
Permalink | Comments (0) | Post RSSRSS comment feed

New Website

New Website



Upgraded the website today to use the asp.net 2.0. I used the small business template from the asp.net website for the site look. Posted it on the KJM Solutions server. I am using SQL Server 2005 for the blog now. We are getting closer to opening up for business.


Be the first to rate this post

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

Categories: Archive
Posted by Ken Tucker on Monday, February 13, 2006 12:42 PM
Permalink | Comments (0) | Post RSSRSS comment feed

Custom Sort of DataGridView

Custom Sort of DataGridView



Someone asked me about doing a custom sort on a datagridview during my datagridview session at code camp. Unfortunately this will not work if the datagridview is bound to a datasource. This example numbers as string data to a datagridview. When you sort this column the values will not be in numeric order. This example converts the string to a number and sorts based on the number.




Public Class Form1

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        DataGridView1.ColumnCount = 1
        DataGridView1.Columns(0).HeaderText = "String"

        For x As Integer = 0 To 100
            DataGridView1.Rows.Add(New String() {x.ToString})
        Next
    End Sub

    Private Sub DataGridView1_SortCompare(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewSortCompareEventArgs) Handles DataGridView1.SortCompare
        Dim intValue1, intValue2 As Integer
        If Not Integer.TryParse(e.CellValue1.ToString, intValue1) Then Return
        If Not Integer.TryParse(e.CellValue2.ToString, intValue2) Then Return
        If intValue1 = intValue2 Then
            e.SortResult = 0
        ElseIf intValue2 > intValue1 Then
            e.SortResult = -1
        Else
            e.SortResult = 1
        End If
        e.Handled = True
    End Sub
End Class

 

Be the first to rate this post

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

Categories: DataGridView
Posted by Ken Tucker on Monday, February 06, 2006 11:12 PM
Permalink | Comments (1) | Post RSSRSS comment feed