This tutorial was created with Microsoft's LINQ Community Technology Preview release, which can be downloaded from here
If you're looking for a really good web host, try Server Intellect - we found the setup procedure and control panel, very easy to adapt to and their IT team is awesome!
In this introduction, we will introduce you to LINQ in a Windows Form. We are going to use LINQ to get and filter data from a String Array.
The first thing we do after installing the LINQ release above, is to start a new project > Visual Basic LINQ Windows Application.
In this example, we are going to create a string array with a list of names for the data source. Then we are going to filter the data by the length of the names, giving the user the chance to set the number of letters. So we will add a textbox, two labels, a button and a list box.
The form should look something like this:

Now we have our form, we can add the logic to the code-behind. Under the button click event we add the following:
Dim names() As String = {"Michael", "Tina", "Zach", "Ella", "Olivia", "Anthony", "Andrew"}
Dim namesWithFourCharacters As IEnumerable(Of String) = From name In names _
Where Name.Length < Convert.ToInt16(TextBox1.Text.ToString()) _
Select Name
lstNames.Items.Clear()
For Each Name As String In namesWithFourCharacters
lstNames.Items.Add(Name)
Next Name
Label1.Text = "Names with letters less than " & TextBox1.Text & ":" |
This code creates a string array of names, and then the LINQ code selects only the names with the length (number of letters) less than what the user entered. The list box is cleared before data is entered, to make sure that it's new data each time, and then each name that matches the query is added to the list box.
We used over 10 web hosting companies before we found Server Intellect. Their dedicated servers and add-ons were setup swiftly, in less than 24 hours. We were able to confirm our order over the phone. They respond to our inquiries within an hour. Server Intellect's customer support and assistance are the best we've ever experienced.
We can also add some code to make sure the user enters text. The entire code-behind will look something like this:
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If TextBox1.Text = "" Then
Label1.Text = "Please enter a number."
Else
Dim names() As String = {"Michael", "Tina", "Zach", "Ella", "Olivia", "Anthony", "Andrew"}
Dim namesWithFourCharacters As IEnumerable(Of String) = From name In names _
Where Name.Length < Convert.ToInt16(TextBox1.Text.ToString()) _
Select Name
lstNames.Items.Clear()
For Each Name As String In namesWithFourCharacters
lstNames.Items.Add(Name)
Next Name
Label1.Text = "Names with letters less than " & TextBox1.Text & ":"
End If
End Sub
End Class |