Tuesday 31 July 2012

Microsoft Access tips: ADO Programming Code Examples (SEED)

Microsoft Access tips: ADO Programming Code Examples

How to Distribute Interop.ADOX.dll?

How to Distribute Interop.ADOX.dll?

Saturday 21 July 2012

Create dynamic Form by string with parameters

1- Add 3 forms (form1,form2,form3) to a project, Add one button (button1) to form1

2- In form2, create Sub New as Below

Public Class Form2
 
    Sub New(p1,p2,p3)
 
        ' This call is required by the designer.
        InitializeComponent()
        
        ' Add any initialization after the InitializeComponent() call.
        MsgBox(p1.ToString)
    End Sub
End Class 
 
 
3- In form3, create Sub New as Below

Public Class Form3
 
    Sub New(p1,p2)
 
        ' This call is required by the designer.
        InitializeComponent()
        
        ' Add any initialization after the InitializeComponent() call.
        MsgBox(p2.ToString)
    End Sub
End Class

4- In form1, in button1_click add this

Private Sub Button1_ClickByVal sender As System.Object,  ByVal e As System.EventArgsHandles Button1.Click
        Dim x = GetFormByStringWithParameter("form2",{1,2,3})
        x.Show
        Dim y = GetFormByStringWithParameter("form3",{22,33})
        y.Show
End Sub

5- The function of GetFormByStringWithParameter is as below (you can put it in form1,or module)

Function GetFormByStringWithParameter(ByVal form_name As String,byval form_parameter() As ObjectAs Form
    Dim FullTypeName     = Application.ProductName & "." & form_name
    Dim FormInstanceType = Type.GetType(FullTypeNameTrueTrue)
    Dim objForm          = CType(Activator.CreateInstance(FormInstanceType,form_parameter),Form)
    Return objForm
End Function


Thursday 12 July 2012

Use Dynamic field in Linq WHERE clause

Sometimes you need to do something like :

SELECT * FROM table WHERE sFieldName = sValue

Here is how to translate the above to LINQ

Dim db As New northwindDataContext    
Dim sFieldName"City"
Dim sFieldValue"Berlin" 
Dim q = From t In db.Customers.AsEnumerable.
        Where(Function(ff.GetType.GetProperty(sFieldName).GetValue(f,Nothing)  = sFieldValue)
        Select t