I wanted to sort elements in a ListBox alphabetically without regard to case. However, Firebird does a case-sensitive sort, and I couldn't get it to recognize UPPER() in the SELECT statement.
One solutions is to add the rows in the table adapter data table to an array of elements of a custom class. The custom class implements IComparable, so when you do Array.sort you can get the case-insensitive order desired. Here's my custom class:
Public Class trendpoint
Implements IComparable
Public name As String
Public description As String
Public Sub New(ByVal name As String, ByVal description As String)
Me.name = name
Me.description = description
End Sub
Public Function CompareTo(ByVal obj As Object) As Integer Implements System.IComparable.CompareTo
Dim comparepoint As trendpoint = CType(obj, trendpoint)
If Me.name.ToUpper < comparepoint.name.ToUpper Then
Return -1
ElseIf Me.name.ToUpper > comparepoint.name.ToUpper Then
Return 1
Else
Return 0
End If
End Function
End Class
Thursday, August 26, 2010
Enable double click event on a ListBox in a vb.net web application
There's a nice concise C# example of supporting double click event on a listbox control in an asp.net web application, here is the equivalent code (for the page load event) in Visual Basic.
If (Not Request.Item("__EVENTARGUMENT") Is Nothing And Request.Item("__EVENTARGUMENT") = "move") Then
Dim idx As Integer = ListBox1.SelectedIndex
Dim item As ListItem = ListBox1.SelectedItem
ListBox1.Items.Remove(item)
ListBox2.SelectedIndex = -1
ListBox2.Items.Add(item)
End If
ListBox1.Attributes.Add("ondblclick", ClientScript.GetPostBackEventReference(ListBox1, "move"))
If (Not Request.Item("__EVENTARGUMENT") Is Nothing And Request.Item("__EVENTARGUMENT") = "move") Then
Dim idx As Integer = ListBox1.SelectedIndex
Dim item As ListItem = ListBox1.SelectedItem
ListBox1.Items.Remove(item)
ListBox2.SelectedIndex = -1
ListBox2.Items.Add(item)
End If
ListBox1.Attributes.Add("ondblclick", ClientScript.GetPostBackEventReference(ListBox1, "move"))
Friday, August 6, 2010
Connecting to a Firebird database from a VB.net 2008 web application
There's a couple of posts related to connecting to a Firebird database from an asp.net 2008 web application that are helpful but not complete.
First, you establish a DSN connection.
When adding the DSN connection the prompts were a little different on my Vista machine than the post describes. First, I picked the Database source
Then, after clicking New Connection button, click Change button on Data Source to switch from SQL Server to ODBC driver
Then, pick the Microsoft ODBC Data Source option
Once this is done when you add a new DSN connection the Firebird/Interbase drivers will be selectable.
During the configuration of the Firebird DSN connection I ran into one other change from the earlier post, rather than browse to the database on the local machine I used the localhost: connection method (e.g. Database = "localhost:c:\program files\ ... \_WEBLINK.FDB")
The Database string is quoted on both ends, in the picture some of the connection string is whited out for (excessive) security.
Now you can follow the second post to establish a data connection
First, you establish a DSN connection.
When adding the DSN connection the prompts were a little different on my Vista machine than the post describes. First, I picked the Database source
Then, after clicking New Connection button, click Change button on Data Source to switch from SQL Server to ODBC driver
Then, pick the Microsoft ODBC Data Source option
Once this is done when you add a new DSN connection the Firebird/Interbase drivers will be selectable.
During the configuration of the Firebird DSN connection I ran into one other change from the earlier post, rather than browse to the database on the local machine I used the localhost: connection method (e.g. Database = "localhost:c:\program files\ ... \_WEBLINK.FDB")
The Database string is quoted on both ends, in the picture some of the connection string is whited out for (excessive) security.
Now you can follow the second post to establish a data connection
Thursday, July 22, 2010
Registry key for IIS subauthenticator is not configured correctly
Installed a Visual Basic web app on a Windows Server 2003 box with IIS 6 today and got some strange intermittent symptoms. The customer could login about 2 times out of 3, and could access some second-level pages intermittently, but other second-level pages would fail immediately. Failures took the user back to the login page.
The Event Viewer showed an error each time the user got bumped back to the login page, saying "Registry Key for IIS subauthenticator is not configured correctly"
I found the Microsoft KB article with instructions to enable IIS management of the anonymous user password. After applying the 3 steps the website works perfectly.
Took a while to resolve because I was baffled by the intermittent nature of the error, but once the correlation to the Event Viewer error was observed it was quick.
The Event Viewer showed an error each time the user got bumped back to the login page, saying "Registry Key for IIS subauthenticator is not configured correctly"
I found the Microsoft KB article with instructions to enable IIS management of the anonymous user password. After applying the 3 steps the website works perfectly.
Took a while to resolve because I was baffled by the intermittent nature of the error, but once the correlation to the Event Viewer error was observed it was quick.
Wednesday, May 19, 2010
Insert multiple records to Microsoft Access database
Did not find a simple answer as to how to insert multiple rows of raw data into an Access database using an Insert Into SQL statement, this post is one of many to point out that VALUES is for single-row inserts, and you need to use a SELECT to insert more than 1 row - which means your values have to already be in the database.
I don't believe there's a straightforward way to do it with a single SQL statement, but you can use free MyOLEDBExpress database editing tool to accomplish it by cutting/pasting your columns of data from Excel spreadsheet or other source directly into a table. If you are combining data with values already in the database you can use a SELECT clause with the INSERT INTO statement to extract the insert values from tables.
It may be worth the effort if you have hundreds of rows of data or more. Here's the Insert statement after the temp table has been created.
INSERT INTO the_Access_Table (field1, field2) SELECT col1, col2 FROM temp_Table INNER JOIN other_Table ....
I don't believe there's a straightforward way to do it with a single SQL statement, but you can use free MyOLEDBExpress database editing tool to accomplish it by cutting/pasting your columns of data from Excel spreadsheet or other source directly into a table. If you are combining data with values already in the database you can use a SELECT clause with the INSERT INTO statement to extract the insert values from tables.
It may be worth the effort if you have hundreds of rows of data or more. Here's the Insert statement after the temp table has been created.
INSERT INTO the_Access_Table (field1, field2) SELECT col1, col2 FROM temp_Table INNER JOIN other_Table ....
Thursday, March 25, 2010
VB.net Opening Connection to SQLServer
Was unable to connect from Visual Basic .NET 2008 to a SQL Server Express 2008 database using the online examples. I was getting the error "network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible"
Changing from Data Source=(local) to Data Source=.\SQLEXPRESS fixed the issue
Full example:
Dim myConnection As SqlConnection
Dim myCommand As SqlCommand
Dim dr As SqlDataReader
myConnection = New SqlConnection("Data Source=.\SQLEXPRESS;User ID=youruser;Password=yourpassword;Initial Catalog=yourdatabase")
Try
myConnection.Open()
myCommand = New SqlCommand("Select * from tblRoom", myConnection)
dr = myCommand.ExecuteReader()
While dr.Read()
MessageBox.Show("Field1 " & dr(0).ToString() & " Field2 " & dr(1).ToString())
End While
dr.Close()
myConnection.Close()
Catch e As Exception
'handle errors
End Try
Changing from Data Source=(local) to Data Source=.\SQLEXPRESS fixed the issue
Full example:
Dim myConnection As SqlConnection
Dim myCommand As SqlCommand
Dim dr As SqlDataReader
myConnection = New SqlConnection("Data Source=.\SQLEXPRESS;User ID=youruser;Password=yourpassword;Initial Catalog=yourdatabase")
Try
myConnection.Open()
myCommand = New SqlCommand("Select * from tblRoom", myConnection)
dr = myCommand.ExecuteReader()
While dr.Read()
MessageBox.Show("Field1 " & dr(0).ToString() & " Field2 " & dr(1).ToString())
End While
dr.Close()
myConnection.Close()
Catch e As Exception
'handle errors
End Try
Friday, December 4, 2009
JDI thread evaluations - Exception processing async thread queue
After some debugging Eclipse may throw an async thread exception every time it hits a breakpoint. The message is along the lines of
JDI thread evaluations
Exception processing async thread queue
You can clean this up by removing all watch statements and all breakpoints and restarting Eclipse.
JDI thread evaluations
Exception processing async thread queue
You can clean this up by removing all watch statements and all breakpoints and restarting Eclipse.
Subscribe to:
Posts (Atom)


