Monday, August 18, 2014

LINQ - An intro to LINQ

LINQ stands for Language Integrated Query. LINQ is a microsoft technology which provides language level support to query any type of datastore (SQL server, XML documents, objects in memory like list of customers, list of orders, arrays, entities, dataset etc)

Suppose we are developing a .Net application which is fetching data from different datasources like SQL XML document, Memory objects etc,then we need to understand the technology and the syntax that is specific for the data source.(Suppose to retrieve data from SQL database we need to understand ADO.net and Transact SQL. To retrieve data from XML document, we need to understand how XPath and XSLT works. Similarly with Memory objects we need to understand how array and generics works.)


The different Types of LINQ:
LINQ to Objects
LINQ to XML
LINQ to DataSet
LINQ to SQL
LINQ to Entities

Friday, August 15, 2014

Working with SQLite in .Net

SQLite is a database engine which is used widely in the software development.
SQLite is also used in Microsoft .net project as it is standalone ,does not require any configuration and is serverless.

To use SQL Lite as your database . you should download SQLite dll from the SQlite website
System.data.SQLite.dll
Once you have downloaded,Add the SQlite dll in the bin directory of your application folder
In Visual studio Right click your project and add reference, Browse and add System.data.SQLite.dll .
The namespace is used is - System.Data.Sqlite.


Thursday, August 14, 2014

How to center a WPF application on center of screen



To center the WPF screen at center add the code at the XAML add attribute WindowStartupLocation and set its property to CenterScreen

WindowStartupLocation="CenterScreen"


<Window x:Class="DemoApplicationMainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

        Title="MainWindow" Height="800" Width="850" WindowStartupLocation="CenterScreen"  MaxHeight="9000">

Code to create a single instance of WPF application



Code to create a Single instance of Windows Application in WPF
To create a single instance first we need to check if there is any instance is already running and kills the current process to stop creating multiple instances. This can be achieved by the below code.  

using System;
using System.Diagnostics;
using System.IO;
namespace SingleInstance
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            var exists = Process.GetProcessesByName(System.IO.Path.GetFileNameWithoutExtension(System.Reflection.Assembly.GetEntryAssembly().Location)).Count();

            if(exists > 1)
            {
                MessageBox.Show("An Instance of the application is already running");               
                System.Diagnostics.Process.GetCurrentProcess().Kill();
                return;
            }

            InitializeComponent();
        }
    }
}


Tuesday, August 12, 2014

VB.Net Code to get the installed printers in the network

VB.Net code for Installing printers in the network.


Add namespace: System.Drawing.Printing. 
Add Combo box Control: cbPrinterList
During the Page load: Copy the below code
  For Each Printer As String In PrinterSettings.InstalledPrinters
            cbPrinterList.Items.Add(Printer.ToString())
        Next

Summary:
Imports System.Drawing.Printing
Imports System
Public Class PrinterList
Private Sub PrinterList_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        For Each Printer As String In PrinterSettings.InstalledPrinters
            cbPrinterList.Items.Add(Printer.ToString())
        Next
        cbPrinterList.Text = My.Settings.cbPrinter

    End Sub

Wednesday, April 23, 2014

How to create table in Blogger

In this article we will learn "How to create a table in a Blogger"
  1. To create a basic table of row 2 and column 2
  •  In the Blogger go to a new post or an existing post where you want to create a table
  • Click on "HTML" tab on your blogger editor
  • Below code can be used to create a basic table of 3 rows and 2 columns.
Header Row 1 Header Row 2
Row1 Col1 Row1 Col2
Row2 Col1 Row2 Col2


<table border="2">
<tbody>
<tr>
<th>Header Row 1 </th>
<th>Header Row 2 </th></tr>
<tr>
<td>Row1 Col1 </td>
<td>Row1 Col2 </td>
</tr>
<tr>
<td>Row2 Col1</td>
<td>Row2 Col2 </td>
</tr>
</tbody>
</table>



  • Format  the table using cell spacing ,cell padding and change of background and border color can be done by adding attributes  bordercolor="#151B54" style="background-color : #BCC6CC"  in  table tag <table border ="2">


Background color and border color can be added to the table with the attributes
<table border="2" cellpadding ="3" cellspacing ="3" bordercolor="#151B54" style="background-color : #BCC6CC" > .The table looks as below.

Header Row 1 Header Row 2
Row1 Col1 Row1 Col2
Row2 Col1 Row2 Col2
  • The table can be formatted as per your blog style by changing the attributes values
<table border="2" cellpadding ="3" cellspacing ="3" bordercolor="#151B54" style="background-color : #BCC6CC;" > 

Your code should look like this

<table border="2" cellpadding="3" cellspacing="3" bordercolor="#151B54" style="background-color: #bcc6cc;">

<tbody>
<tr><th>Header Row 1 </th>
<th>Header Row 2 </th>
</tr>
<tr>
<td>Row1 Col1 </td>
<td>Row1 Col2 </td>
</tr>
<tr>
<td>Row2 Col1</td>
<td>Row2 Col2 </td>
</tr>
</tbody></table>

  • Further to change the row header color add the code in the tr tag of the Header row        <tr style="background-color: #fbb917; color: #810541;">
Your code should look like this

<table border="2" cellpadding="3" cellspacing="3" bordercolor="#151B54" style="background-color: #bcc6cc;">

<tbody>
<tr style="background-color: #fbb917; color: #810541;" ><th>Header Row 1 </th>
<th>Header Row 2 </th>
</tr>
<tr>
<td>Row1 Col1 </td>
<td>Row1 Col2 </td>
</tr>
<tr>
<td>Row2 Col1</td>
<td>Row2 Col2 </td>
</tr>
</tbody></table>
    Header Row 1 Header Row 2
    Row1 Col1 Row1 Col2
    Row2 Col1 Row2 Col2

  • You might see white space above the table to remove the extra space above the table .Add the <style> tag above the table and enclose the table with div tags.
<style type="text/css"> .TableSpace br{display:none}
</style>
<div class="TableSpace">
<table border="2" cellpadding ="3" cellspacing ="3" bordercolor="#151B54" style="background-color : #BCC6CC" >
<tbody>
<tr>
<th>Header Row 1 </th>
<th>Header Row 2 </th></tr>
<tr>
<td>Row1 Col1 </td>
<td>Row1 Col2 </td>
</tr>
<tr>
<td>Row2 Col1</td>
<td>Row2 Col2 </td>
</tr>
</tbody>
</table>
</div>