Ichikuma's blog

生活實況紀錄

By

Bind DLINQ to DataGridView

This morning I try to find a method to bind DLINQ to DataGridView. There don’t have ToBindingList in DLINQ DataQuery. Need to manually import System.Data.Dlinq.DataQueryExtensions in the top of form

	Imports System.Data.Dlinq.DataQueryExtensions

After that, the method ToBindingList() will come out.

        Dim sConnectString As String = "data source=.\SQLEXPRESS;" & _
                 "Integrated Security=SSPI;AttachDBFilename=D:\Data\Northwind.mdf;" & _
                 "User Instance=true"
        Dim db As New Northwind(sConnectString) 

        Dim cust = From c In db.Customers _
                 Select c

        DataGridView1.DataSource = cust.ToBindingList()
        DataGridView1.Refresh()

So now, I can modify this to bind the DataQuery to BindingSource for my form.

By

VB.NET LINQ == RUBY?

I have write a simple program in VB.Net LINQ and Ruby, which product the result is same. If you study the code both syntax almost same. I think nowaday all programming langauge is going to ruby-like programming language (easy to understand and real object-oriented programming).

VB.Net

Dim v as Integer
Dim numbers As Integer() = New Integer() {1, 4, 2, 7, 8, 9}
Dim evenNumbers = From p In numbers _
       Where (p Mod 2) = 0 _
       Select P
For Each v In evenNumbers
   System.Console.WriteLine(v)
Next

Ruby

numbers = [1,4,2,7,8,9]
evenNumbers = Array.new
numbers.each do |p|
 evenNumbers<<p if (p % 2) == 0
end
evenNumbers.each {|p| print p}