How can create Array in VB.Net & C# ?

ms_visual_studio    There are different ways that you can create array , here I am going to explain them for you
1.You can supply the array size when you are declaring it , as the following example shows.

[VB.NET]

        Dim cargoWeights(10) As Double 

        Dim atmospherePressures(2, 2, 4, 10) As Short 

        Dim inquiriesByYearMonthDay(20)()() As Byte

[C#]

        double[] cargoWeights = new double[11];

        short[,,,] atmospherePressures = new short[3, 3, 5, 11];

        byte[][][] inquiriesByYearMonthDay = new byte[21][][];

2.You can also use a New clause to supply the size of an array
 when it’s created, as the following example shows.

[VB.NET]

          cargoWeights = New Double(10) {}

          atmospherePressures = New Short(2, 2, 4, 10) {}

          inquiriesByYearMonthDay = New Byte(20)()() {}

[C#]

          cargoWeights = new double[11];

          atmospherePressures = new short[3, 3, 5, 11];

          inquiriesByYearMonthDay = new byte[21][][];

What Is SSL (Secure Sockets Layer) ?

SecurityIn this post I am going to talk about SSL , Each programer specially web Programmer must know about the SSL.

What Is SSL ? 
SSL is a security standard that makes a secure connection between Server and Client , for
example web server (website) and a browser; or a mail server and a mail client (e.g., Outlook).

SSL can guarantee that confidential information same as Credit Card Number , Security numbers and any sensitive information to be transmitted securely.

How does it work?

SSL Certificates have two keys: a public and a private key. These keys work together to make a secure and encrypted connection.

You must create a Certificate Signing Request (CSR) on your server. The CSR makes the private key and a CSR data file that you should send it to the SSL Certificate issuer (Certificate Authority or CA). A public key is created by CA to match your private key without compromising the key itself.  The private key is not seen by CA.

Caution!
Anyone can create certificate but browsers only trust certificates that are signed by organization which are in the list of trusted CAs.

How to create cookie in VB.Net & C#

Cookie is  one of the useful object that can be used in the web application, and you can use it to save user setting on the local computer or device.

 Before create any Cookie please read these hints:
1. This part was copied directly from Cookie Law :
  Cookie laws have changed with effect from 26th May 2011.
On 26th May 2011, new laws came into force in the UK that affect most web sites. If cookies are used in a site, the Privacy and Electronic Communications (EC Directive) (Amendment) Regulations 2011 (UK Regulations) provide that certain information must be given to that site’s visitors and the user must give his or her consent to the placing of the cookies…..
For further information please go to  the Cookie Law
2. Programmers have not to save sensitive(confidential) information same as Username, Password, Credit card number or something like that in the Cookies.
Seat your belt we want to finish this part rapidly 🙂
Different parts of Cookies:
 1. Name: each Cookie must has the specific name.
2. Value: Each Cookie has specific value, without value Cookie does not have meaning.
3 Expire Date: .Each Cookie must have Expire date, we do not want to save a Cookie for ever!
Before you create a Cookie must check the Cookie existent, if the Cookie already is exits no need to create it again, you just have to update the value or Expire date.
[VB.NET]

 Private Sub CreateCookies()

        If Request.Cookies("UserName") Is Nothing Then

            Dim aCookie As New HttpCookie("UserName")

            aCookie.Value = "MyUsername"

            aCookie.Expires = DateTime.Now.AddDays(30)

            Response.Cookies.Add(aCookie)

        Else

            Dim cookie As HttpCookie = HttpContext.Current.Request.Cookies("UserName")

            cookie.Value = "UserName"

            cookie.Expires = DateTime.Now.AddDays(30)

            Response.Cookies.Add(cookie)

        End If

    End 
Sub

[C#]

private void CreateCookies()

{

    if (Request.Cookies("UserName") == null) {

        HttpCookie aCookie = new HttpCookie("UserName");

        aCookie.Value = "MyUsername";

        aCookie.Expires = DateTime.Now.AddDays(30);

        Response.Cookies.Add(aCookie);

    } else {

        HttpCookie cookie = HttpContext.Current.Request.Cookies("UserName");

        cookie.Value = "UserName";

        cookie.Expires = DateTime.Now.AddDays(30);

        Response.Cookies.Add(cookie);

    }

}

//

How can Connect to the SQL Server and Run Commands in VB.Net & C# ?

If you have difficulty to connect to the SQL Server, read this post, it can help you to understand the fundamental:
First let me to explain the basic objects:
1.SqlConnection
This objects contains SQL Connection String, other objects use this object to connect to the SQL Server
2.SqlCommand
This object contains SQL Commands that will be run, it can carry SQL commands or Stored procedure name.
3. SqlDataAdapter
If you want to run Commands that return data (records), you should use this object, it can bring data from SQL Server to your application

now we are familiar with the basic objects that we need to connect to the SQL Server, let start to write the function that run the SQL command for us.

[VB.NET]

Private Sub ConnectToSQLServer()
Try
            Dim SqlConnection As New Data.SqlClient.SqlConnection(
"Integrated Security=SSPI;Persist Security Info=False;Initial 
Catalog=Diet;Data Source=.\server2008")
            Dim SQLcommand As New Data.SqlClient.SqlCommand("SELECT * FROM Foods", SqlConnection)
            Dim SqlDataAdapter As New Data.SqlClient.SqlDataAdapter(SQLcommand)
            Dim DtResult As New DataTable
            SqlConnection.Open()
            SqlDataAdapter.Fill(DtResult)
            SqlConnection.Close()
        Catch ex As Exception
            Throw ex.InnerException
        End Try
    End Sub

[C#]
private void ConnectToSQLServer()
{
    try {
        System.Data.SqlClient.SqlConnection SqlConnection = new System.Data.SqlClient.SqlConnection
("Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=Diet;Data Source=.\\server2008");
        System.Data.SqlClient.SqlCommand SQLcommand = 
           new System.Data.SqlClient.SqlCommand("SELECT * FROM Foods", SqlConnection);
        System.Data.SqlClient.SqlDataAdapter SqlDataAdapter =
          new System.Data.SqlClient.SqlDataAdapter(SQLcommand);
        DataTable DtResult = new DataTable();
        SqlConnection.Open();
        SqlDataAdapter.Fill(DtResult);
        SqlConnection.Close();
    } catch (Exception ex) {
        throw ex.InnerException;
    }
}