Sunday, August 19, 2007

Using GetSchemaTable to get Info about Columns in VB.NET

Here is a simple example in VB.NET that uses GetSchemaTable to retrieve information about the columns returned from a SQL Select statement. If you say "Select * from table", this method is useful for learning what information you will have returned. For a C# example and more information on the topic, look here.

Dim myConn As New OleDbConnection(ConnectionString)

Dim sql As String = "Select * from Table_ABC"

Dim myCommand As New OleDbCommand(sql, myConn)

myConn.Open()

Dim objDR As OleDbDataReader

objDR = myCommand.ExecuteReader(CommandBehavior.CloseConnection)


' Retrieve column schema into a DataTable.
Dim schemaTable As DataTable
schemaTable = objDR.GetSchemaTable()

' For each field in the table...
For Each myField As DataRow In schemaTable.Rows

' For each property of the field...
For Each myProperty As DataColumn In schemaTable.Columns

'Display the field name and value.
Debug.WriteLine(myProperty.ColumnName + _
" = " + myField(myProperty).ToString())

Next

Debug.WriteLine("")

Next

Wednesday, August 15, 2007

ceReg now supports REG_MULTI_SZ

With version 3.0.0.7 of the Srego CE Toolpack Command-Line utilities, the ceReg utility supports reading and writing of the Multiple String type (REG_MULTI_SZ) in the device's registry. The REG_MULTI_SZ type allows a list of delimited strings to be stored in one value. Mimicking the Reg command on the desktop, multiple strings are specified with a "\0" delimiter:

phone\0fax\0mail

In the Remote Registry Editor, the Multi String value looks like:




Reading a Multi String value is also similar to the desktop's Reg command:

ceReg /r /1 /sub software\srego\test /name testValue

ceReg - version 03.00.00.07
(c) Srego, Inc - 2007

[HKEY_CURRENT_USER\software\srego\test]

"testValue"="fax\0mail\0phone\00