Sign up to the jQuery Grid Subscription list.

What is an optimizer in MS SQL server ?

Original post by sam.SQL at

The question:

What does mean by Optimizer in MS SQL ? What is it ?
How do you use it ? what are the benifits of use it ?

The accepted answer by Derekman:

The query optimizer is the component of SQL server that determines the most efficient way to execute a query based upon the distribution statistics and histograms maintained within sql server. When you pass a query to sql server the query is optimized based on the estimated "cost" of the query for the different possible ways to exeute the statement based on the table(s) and index(es) available. SQL Server query optimizer reviews the different options in which to execute the query and decides on the most efficient way based on overall cost. Most, but not all, queries are optimized automatically and you do not need to do anything to invoke query optimization. There are however "query hints" that allow you to over ride a query plan recommended by the optimizer.

Please review BOL and the below link for a more detailed explanation.

Best of Luck!!

Add registry key and delete it with

Original post by Natural_Orange at

The question:

My program has an option for running at startup.
I need a way to add a registry key to:
And Remove it as well.

I've looked in to some other stuff but it seems way to complicated for what i need.

The accepted answer by Moayad Mardini:

To add a value to that key :

My.Computer.Registry.SetValue("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run", YourProgramName, YourProgramPath, Microsoft.Win32.RegistryValueKind.String)

Then to delete it :

My.Computer.Registry.CurrentUser.OpenSubKey("Software\Microsoft\Windows\CurrentVersion\Run", True).DeleteValue(YourProgramName)

Hope this helps

How to add a new record (

Original post by Jarge at

The question:

Ok i have an unbound text box

i also have a command button that does nothing.

I need to be able to have whatever i type into the text box to be entered into a table.

how can i do this?

for the record i know extremely little about VBA, i can copy and paste, and edit bits if im told what, when and where to edit but apart from that i'm useless.

Any help will be greatly appreciated.

The accepted answer by Spotty:

From what you said, you are leaving out real important points

A table, what sort of database are you using, does you applicable actually already use the database in any way already ?

What version of VB are you using ?

All these points determine a solution. The technology you are probably going to be using is called ADO.NET and you are going to be using a Command Object. A web search on ADO.NET + VB.NET + INSERT QUERY will probably reveal quite a few basic examples.

Something a simple as may work.
Dim con As SqlConnection
con = New SqlConnection("Server=(local)\SQLEXPRESS;Initial Catalog=MyDatabase;Integrated Security=SSPI")
Dim cmd As New SqlCommand()
cmd.Connection = con
cmd.CommandText = "INSERT INTO Employee (FirstName) VALUES (@FirstName)"
' 2. Map parameters
cmd.Parameters.Add("@FirstName", SqlDbType.NVarChar, 10, "FirstName")
cmd.Parameters("@FirstName").Value = Textbox1.text
End Try

List Currently Opened Windows with

Original post by Jupiter13 at

The question:

I am trying to list all of the currently open windows that are in the taskbar. Does anybody know how to do that?

Thanks in advance.

The accepted answer by Tall Dude:

If you just want the applications,

(not all windows,) try:

Public Class Form1

' Derived from code at:


Declare Function EnumWindows Lib "user32" _

(ByVal lpEnumFunc As CallBack, ByVal lParam As Integer) As Integer

Declare Function GetForegroundWindow Lib "user32" () As Integer

Declare Function GetParent Lib "user32" (ByVal hwnd As Integer) As Integer

Declare Function GetWindow Lib "user32" _

(ByVal hwnd As Integer, ByVal wCmd As Integer) As Integer

Declare Function GetWindowInteger Lib "user32" Alias "GetWindowLongA" _

(ByVal hwnd As Integer, ByVal nIndex As Integer) As Integer

Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" _

(ByVal hwnd As Integer, ByVal lpString As String, ByVal cch As Integer) As Integer

Declare Function IsIconic Lib "user32" (ByVal hwnd As Integer) As Integer

Declare Function IsWindowVisible Lib "user32" (ByVal hwnd As Integer) As Integer


' Constants used with APIs


Public Const SW_SHOW = 5

Public Const SW_RESTORE = 9

Public Const GW_OWNER = 4

Public Const GWL_HWNDPARENT = (-8)

Public Const GWL_EXSTYLE = (-20)

Public Const WS_EX_TOOLWINDOW = &H80

Public Const WS_EX_APPWINDOW = &H40000


Public Delegate Function CallBack(ByVal hwnd As Integer, ByVal lParam As Integer) As Boolean

Public Shared Function fEnumWindowsCallBack(ByVal hwnd As Integer, ByVal lParam As Integer) As Boolean

Dim lReturn As Integer

Dim lExStyle As Integer

Dim bNoOwner As Boolean

Dim sWindowText As String


' This callback function is called by Windows (from

' the EnumWindows API call) for EVERY window that exists.

' It populates the listbox with a list of windows that we

' are interested in.


' Windows to display are those that:

' - are not this app's

' - are visible

' - do not have a parent

' - have no owner and are not Tool windows OR

' have an owner and are App windows


If hwnd <> Form1.Handle Then

If IsWindowVisible(hwnd) Then

If GetParent(hwnd) = 0 Then

bNoOwner = (GetWindow(hwnd, GW_OWNER) = 0)

lExStyle = GetWindowInteger(hwnd, GWL_EXSTYLE)

If (((lExStyle And WS_EX_TOOLWINDOW) = 0) And bNoOwner) Or _

((lExStyle And WS_EX_APPWINDOW) And Not bNoOwner) Then


' Get the window's caption.


sWindowText = Space$(256)

lReturn = GetWindowText(hwnd, sWindowText, Len(sWindowText))

If lReturn Then


' Add it to our list.


sWindowText = Trim(sWindowText)


End If

End If

End If

End If

End If

fEnumWindowsCallBack = True

End Function

Private Sub Button1_Click(ByVal sender As System.Object, _

ByVal e As System.EventArgs) Handles Button1.Click


EnumWindows(AddressOf fEnumWindowsCallBack, 0)

End Sub

End Class

convert binary to octal ,hexadecimal and decimal numbers

This is the second part of the previous question.

The response by Martin Xie - MSFT:

By means of Convert class, you can first convert Binary to Decimal Intger, and then convert Decimal to Octal and Hexadecimal string.

Imports Microsoft.VisualBasic

Imports System

Imports System.Collections.Generic

Imports System.Text

Friend Class Program

Shared Sub Main(ByVal args As String())

Dim bin As String = "1000001" 'Binary string

Dim decimalValue As Integer

Dim hexValue As String

Dim OctalValue As String

decimalValue = Convert.ToInt32(bin, 2) 'First convert Binary to Decimal Intger

Console.WriteLine("Decimal:" & decimalValue)

OctalValue = Oct(decimalValue) 'Convert Decimal to Octal string

Console.WriteLine("Octal:" & OctalValue)

hexValue = Hex(decimalValue) 'Convert Decimal to Hexadecimal string

Console.WriteLine("Hexadecimal:" & hexValue)


End Sub

End Class

The output will be:

Decimal: 65

Octal: 101

Hexadecimal: 41

Convert ASCII Code/Character to Binary Number

Original post by rattlesnake316 at

The question:

Hello! Hope someone could help me on converting ASCII characters to Binary
Also,hope you know how to convert Boolean Number to Octal or Hexadecimal or Decimal number.
Thanks in advance!

The accepted answer by Martin Xie - MSFT :

Hi rattlesnake,

ASCII can only represent character codes between 0 and 127.

About converting ASCII characters to Binary,

e.g. convert AscII value 66 of character B to Binary like this:

Imports Microsoft.VisualBasic

Imports System

Imports System.Collections.Generic

Imports System.Text

Friend Class Program

Shared Sub Main(ByVal args As String())

Dim myChar As Char = "B"c

Dim j As Integer = 0

Dim ascii As Integer = System.Convert.ToInt32(myChar)

Console.WriteLine("ASCII:" & ascii)

Dim binTempResult As String = ""

Do While ascii > 0

j = ascii Mod 2

binTempResult &= j.ToString()

ascii = ascii \ 2


'reverse output

Dim arr As Char() = binTempResult.ToCharArray()


Dim binResult As String = New String(arr)



End Sub

End Class

The output will be:



Problem applying a filter to binding source

The original post by Kelly R. Martin at

The question:

Upon updateing a combobox to select the sex of a farm animal I am attempting to filter out the opposite sex in the next ID box.Can anyone see where my issue is here. I have rewritten this many time to no avail. I have read through the msdn help on this and all appears to be done correctly. Also... How would I use one of these filters to show only discrete items?

And here is the code

Public Class Form1

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

'TODO: This line of code loads data into the 'Ct10DataSet.animal' table. You can move, or remove it, as needed.


End Sub

Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged

Me.AnimalBindingSource1.Filter = "Sex = " & ComboBox1.SelectedValue.ToString()

End Sub

End Class

The Accepted answer by ahmedilyas :

try this:

Me.AnimalBindingSource1.Filter = "Sex = '" & ComboBox1.Text & "'"

The digg button added

We finally added the digg button. Please digg only posts that you read, so you help us spread the net.
How we installed the Digg button on blogger?
Find out here how this has been done :

Resize datagrid content to take up the entire datagrid control

Original post by Wopfather at

The Question:

I have a form with datagrid on it, but when i fill the grid with a table, the columns do not take up the entire space that is available in the datagrid. Also the individual column sizes do not show all the data in the field, i have to resize it using drag feature, but i have the space on the form when i first load it and i want the columns to take up all the space available in the datagrid.

The accepted answer by Riquel Dong – MSFT:

Based on your post, you need to change the width of the row or column in a DataGrid. You can use the DataGridTableStyle class to implement this.

it represents the table drawn by the System.Windows.Forms.DataGrid control at run time. Its property GridColumnStyles allows you to create a customized set of column styles. Pleaser read this article Advanced DataGrid Sizing for this problem. It shoulds help your to handle this problem. Here is the code exmaple about sizing the datagrid control. Hope this helps.

Public Class Form5

Dim dt As DataTable

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

DataGrid1.Width = 450

dt = New DataTable

dt.Columns.Add("id", GetType(Integer))

dt.Columns.Add("name", GetType(String))

dt.Columns.Add("region", GetType(String))

For i As Integer = 0 To 5

dt.Rows.Add(i, "name " & i.ToString, "region " & i.ToString)


Dim style As DataGridTableStyle = New DataGridTableStyle()

style.MappingName = dt.TableName

For Each column As DataColumn In dt.Columns

Dim gridColumn As DataGridTextBoxColumn = New DataGridTextBoxColumn()

gridColumn.MappingName = column.ColumnName

gridColumn.HeaderText = column.ColumnName

gridColumn.Width = 135





DataGrid1.DataSource = dt

End Sub

End Class

Best regards,



MSDN Tracker Blog:

Blog aim:
Our blog quest is to keep in track of all successful and answered post in the MSDN Forums.
So you can easily get the top answers from this blog. We have 20 post in different categories, just make a search and you should find what you are searching for!
Having a good tutorial or article about MS technology?
We'll post you article on our blog! Just leave a comment including your tutorial address and I'll post it here. You'll get also a link ;)
You can also send it to me by email:

Other Dot Net blogs:
The Dot Net Source
My Blogger
My Wordpress

Blog traffic: For webmasters
December 2007 : 1 080 visitor ( 1 230 page views)
January 2008 : 1 633 visitor ( 2 036 page views)
February 2008 : 2 010 ( 2 885 page views)
March 2008 : 2 660 ( 3 125 page views)
April 2008 : 3 210 ( 4 452 page views)
May 2008 : 3 885 ( 5 062 page views)