Monday, May 18, 2009

TechEd 2009 in Los Angeles



This year the TechEd Developers Conference was merged with the TechEd IT conference and happened last week in Los Angeles. While there were significantly fewer Developer oriented sessions, it was interesting to sit in some of the IT sessions. With around 700 sessions to choose from and only about 20 you can actually attend, the need to be particular about what you want to learn becomes very important. I heavily weighted my track with “Mobile”, but I also checked out SQL Server’s Spatial capabilities, and the future directions of the development environments and programming languages.

The push, I mean focus, this year was definitely the yet to be released Windows 7 and Windows Server 2008 R2, followed by a healthy dose of Virtualization in the form of Hyper-V and Windows Virtual PC.

I did have an opportunity to run my apps on a beta copy of Windows 7 at the “Bring Your Own App Lab.” There were a few glitchy things with reading some values out of the registry, but overall I was very pleased with how my apps worked the first time on Windows 7. I have already checked off a lot of grief on my to-do list from this experience. The free booze they were passing out was not even necessary to favorably color my opinion of Windows 7.

The focus last year was definitely LINQ, which seems to have been toned down now to is actual value. WPF and Silverlight, looked cool to try, but now they look usable. Microsoft’s creation of tools to help spawn the development of new programming languages is supposed to bring about an explosion in new languages. I along with everyone else in the Polyglot Programmer session cringed at the idea of having to learn dozens of new languages, but like LINQ, this idea may fade into a manageable and productive tool in our programming arsenal. I was hoping to see Windows Workflow (WF) be a hotter topic than it apparently is, but it may take a few iterations before it catches on.

I was pretty pleased with TechEd 2009. I will continue to process the information for a while.



Tuesday, May 5, 2009

Scaling one Rectangle to fit in Another Rectangle

Here is a great posting that shows several approaches to scaling one rectangle to fit inside of another:

http://www.vbdotnetforums.com/graphics-gdi/33829-scale-rectangle-fit-another.html

Monday, April 13, 2009

GetComputerName equivalent in VB.NET and C#

The Win32Api GetComputerName has a simpler equivalent in the .NET world:



Dim compName as String = Environment.MachineName.ToString

Wednesday, April 8, 2009

Getting the Version of an OleDB Provider

There may a much simpler way of determining the version of an OleDb provider (like OraOledb.Oracle.1) than I have shown below, but I have yet to find one.

The OleDbConnection object will tell you the version of the Server through its ServerVersion property:

Dim myConn As New OleDbConnection(g_gtech.GetConnectionString)
myConn.Open()
Dim versionStr as String = myConn.ServerVersion.ToString
myConn.Dispose()


But, I often want to the know the version of the Provider itself. The only way I have found to do this is to sift through the registry and read the ProductVersion off the provider DLL itself.

For example:

Dim versionStr as String = _
GetProviderVersion("OraOleDb.Oracle.1")

Here is the supporting code:


Public Function GetProviderVersion(ByVal providerName As String) As String

Try
Dim clsid As String = GetRegistryValue(Registry.LocalMachine, _
"SOFTWARE\Classes\" + providerName + "\clsid", "")

If clsid.Trim = "" Then Return "Not Installed"
Dim path As String = _
GetRegistryValue(Registry.LocalMachine, "SOFTWARE\Classes\CLSID\" + clsid + "\InprocServer32", "")

Dim Info As FileVersionInfo
Info = FileVersionInfo.GetVersionInfo(path)
Return Info.ProductVersion.ToString

Catch ex As Exception

Return "Unable to get Version"

End Try

End Function

Public Function GetRegistryValue(ByVal regKey As RegistryKey, _
ByVal subKey As String, ByVal valueName As String) As String

Dim value As String = ""
Dim registryKey As RegistryKey = regKey
Dim registrySubKey As RegistryKey
registrySubKey = registryKey.OpenSubKey(subKey)
If registrySubKey IsNot Nothing Then
Try
value = registrySubKey.GetValue(valueName).ToString
Catch ex As Exception
value = ""
End Try
registrySubKey.Close()
End If
Return value
End Function

If there is a simple or more elegant way to find the Provider version, please comment.

Friday, March 27, 2009

Setting the DateTimePicker to a Blank Value

I wanted to use the DateTimePicker control on a data entry form; however, it always has to be set to a value. I did not want to set the date value to Now or some other preset value because it is not clear to the user that the value needs to be set. I found several solutions to this problem, but the one below appears to work and is easy to use.

Initialize the DateTimePicker control to a blank value by setting the Format property to Custom and the CustomFormat property to a space (" "):

DateTimePickerConstDate.CustomFormat = " "
DateTimePickerConstDate.Format = DateTimePickerFormat.Custom


Then, when the value changes, change the Format property back to its original value (or define a usable Custom Format:

Private Sub DateTimePickerConstDate_ValueChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DateTimePickerConstDate.ValueChanged

DateTimePickerConstDate.Format = DateTimePickerFormat.Short

End Sub


For more information on this solution and other approaches, see the following:

http://social.msdn.microsoft.com/Forums/en-US/netfxcompact/thread/46b2a370-72ec-485c-9361-bfa505bb6863/

Sunday, March 22, 2009

Sorting a VarChar Attribute as a Number in a SQL Statement

This post is not particularly .NET, but I am posting it anyway.

I was needing to sort the results of a SQL statements by a Priority attribute (which has the values 1 to 10). Unfortunately, the Priority attribute is defined as VarChar, so 10 always follows 1 when you do an ORDER BY Priority.

There are many solutions to this problem, but this simplest (although not the more readily obvious, and maybe not the most efficient) is this:

SELECT * FROM Data_Table ORDER BY Len(Priority), Priority ASC

Another approach is:

SELECT * FROM Data_Table ORDER BY RIGHT('0000' + RTRIM(LTRIM(Priority)), 4)


There are other approaches in the posts where I found this solution:

http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=81901

http://www.eggheadcafe.com/conversation.aspx?messageid=29907381&threadid=29907381

Thursday, February 12, 2009

Appending a File with StreamWriter

The StreamWriter class has an Append flag that can be set to append to the file:


Dim outfile As New StreamWriter(filename, True)


The are other overloaded versions with the append flag as well.