How to count list of the tables in SQL Server Database

Get the total number of table count in Database

USE yourDataBaseName
SELECT COUNT(*) from information_schema.tables
WHERE table_type = 'base table'

Get the total number of table Name in Database

USE yourDataBaseName
GO
SELECT *
FROM sys.Tables
GO

How to use Lamda expression instead of If Condition in C#


Normal IF Condition
protected void Page_Load(object sender, EventArgs e)
    {
        int id = 1;
        int k=2;
        int j = 3;
      
         if ( id  > 2)
        {
            Response.Write(k);
        }
        else
        {
            Response.Write(j);
        }
    }

Lamda Expression
protected void Page_Load(object sender, EventArgs e)
    {
        int id = 1;
        int l;
        int k=2;
        int j = 3;
       
        // Here my if condition   (?)  it is true execute k , False execute j.  The value store into variable l.
        l = (id > 2) ? k : j;

        Response.Write(l);
    }

what is the difference between asp.net and mvc

If a 3-tier design were like this:
Client <-> Middle <-> Data
the MVC patter would be:
     Middle
     ^    |
     |    v
Client <- Data
Meaning that:
  • in the 3-tier equivalent, communication between layers is bi-directional and always passes through the Middle tier
  • in the MVC equivalent the communication is in unidirectional; we could say that each "layer" is updated by the one at the left and, in turn, updates the one at the right –where "left" and "right" are merely illustrative
P.S. Client would be the View and Middle the Controller


for more reference about the mvc 
http://weblogs.asp.net/scottgu/archive/2007/11/13/asp-net-mvc-framework-part-1.aspx 

how to Execute Multiple Queries on a Single Connection?

public void Save()
{
    int hit = 0;
        using (SqlConnection conn = new SqlConnection(WebConfigurationManager.ConnectionStrings["dbconnection"].ConnectionString))
        {
            SqlCommand cmd = new SqlCommand("SELECT TOP 1 * from Hitcount order by id desc", conn);
            SqlCommand command = new SqlCommand("insert into Hitcount(Name,Hit)values(@Name,@hit)", conn);

            conn.Open();

            SqlDataReader rdr = cmd.ExecuteReader();
            if (rdr.Read())
            {
                hit = Convert.ToInt32(rdr["hit"]);
                hit = hit + 1;
                rdr.Close();
            }

            command.Parameters.AddWithValue("@Name", "default");
            command.Parameters.AddWithValue("@hit", hit);
            command.ExecuteNonQuery();

            conn.Close();
        }
}


protected void button1_Click(object sender, EventArgs e)
{
    

How to get Client IP Address using C#

    protected string GetIP()
        {

            string localIP = null;
            IPHostEntry localEntry = Dns.GetHostEntry(Dns.GetHostName());
            foreach (IPAddress Ip in localEntry.AddressList)
            {
                if (Ip.AddressFamily.ToString() == "InterNetwork")
                   localIP = Ip.ToString();
               
            }

            return localIP;

        }

protected void Page_Load(object sender, EventArgs e)
        {
            Label1.Text = GetIP();
         }

Real time example for Structure in C#

A struct type is a value type that can contain constructors, constants, fields, methods, properties, indexers, operators, events, and nested types.
Structs are also typically used in graphics/rendering systems. There are many benefits to making points/vectors structs.

public struct Money
{
    public string Currency { get; set; }
    public double Amount { get; set; }
}
public struct PhoneNumber
{
    public int Extension { get; set; }
    public int RegionCode { get; set; }
    //... etc.
}
public struct FullName
{
    public string FirstName { get; set; }
    public string MiddleName { get; set; }
    public string LastName { get; set; }
}

 For more understanding of structure view the following link
http://www.c-sharpcorner.com/UploadFile/rajeshvs/StructuresInCS11112005234341PM/StructuresInCS.aspx

Difference Between SQLClient, OledbClient, ODBCClient

System.Data.SQLClient

Can only be used for connecting to SQL Server 2000 and later. But you will get optimal performance when connecting to those databases.

System.Data.OledbClient

Can be used to connected to SQL 6.5

OLEDBClient gives you ability to connect to other database like ORALCE or Access. But for working with SQL Server you will get better performance using SQLClient.

Note: For connecting to ORALCE Microsoft also has ORACLEClient.


System.Data.ODBCClient
provides connection to legacy databases ( e.g. MS Access 97) using ODBC drivers.

Asp.Net Server Tags

 Asp.Net Inline Expression
http://support.microsoft.com/kb/976112

Here are some helpful links for you on the various tags.

<% %>  An embedded code block is server code that executes during the page's render phase. The code in the block can execute programming statements and call functions in the current page class. http://msdn2.microsoft.com/en-gb/library/ms178135(vs.80).aspx

<%= %> most useful for displaying single pieces of information. http://msdn2.microsoft.com/en-us/library/6dwsdcf5(VS.71).aspx

<%# %> Data Binding Expression Syntax. http://msdn2.microsoft.com/en-us/library/bda9bbfx.aspx

<%$ %> ASP.NET Expression. http://msdn2.microsoft.com/en-us/library/d5bd1tad.aspx

<%@ %> Directive Syntax. http://msdn2.microsoft.com/en-us/library/xz702w3e(VS.80).aspx

<%-- --%> Server-Side Comments. http://msdn2.microsoft.com/en-US/library/4acf8afk.aspx

<%: %> Like <%= %> But HtmlEncodes the output (new with Asp.Net 4). http://weblogs.asp.net/scottgu/archive/2010/04/06/new-lt-gt-syntax-for-html-encoding-output-in-asp-net-4-and-asp-net-mvc-2.aspx