Thursday, 12 June 2014

Difference Between Sql Server VARCHAR and NVARCHAR Data Type

Refer this following link

http://sqlhints.com/2011/12/23/difference-between-varchar-and-nvarchar/

http://social.msdn.microsoft.com/Forums/en-US/b6615caa-629b-45ac-9710-aab7f6e172b3/varchar-and-nvarchar-use-what-is-exact-difference-between-these?forum=sqldataaccess

Monday, 12 May 2014

How to retrieve binary image from database using C# in ASP.NET

Please follow these steps:


Step1: In aspx page add a image control 


<asp:Image ID="img" runat="server"  />

Step2: In code behind add the following code 


protected void Page_Load(object sender, EventArgs e)
        {
            string strCon = ConfigurationManager.ConnectionStrings["DB"].ConnectionString;
            SqlConnection con = new SqlConnection(strCon);
            SqlCommand cmd = new SqlCommand("getimage", con);
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            con.Open();
            if (con.State== ConnectionState.Open)
            {
                cmd.ExecuteNonQuery();
                DataTable dt = new DataTable();
                da.Fill(dt);
                byte[] image = (byte[])dt.Rows[0][0];
                img.ImageUrl = "data:image/png;base64 ," + Convert.ToBase64String(image, 0, image.Length);
            }
           

        }

Step3: In Web.config


<add name="DB"
         connectionString="Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=dbname;Data Source=servername;"
         providerName="System.Data.SqlClient" />

Monday, 28 April 2014

how to get nth highest and lowest salary in sql server

Ex Code: Lowest case :

select top 1 column as 'salary' from (select distinct top 4 column from  Table order by ID asc) a order by ID desc

Highest Case:

select top 1 column as 'salary' from (select distinct top 4 column from  Table order by ID desc) a order by ID asc

Tuesday, 1 April 2014

linq get second highest number or salary

Use this query:

var employees = Employees
    .GroupBy(e => e.Salary)
    .OrderByDescending(f => f.Key)
    .Skip(1).Take(1)
    .First();

Friday, 28 March 2014

how to count number of online users in asp.net

Simple two steps:

1.Add this code in Global.asax


void Application_Start(Object Sender, EventArgs E)
        {
            Application["CurrentUsers"] = 0;
        }
        void Session_OnStart(object Sender, EventArgs E)
        {
            Application.Lock();
            Application["CurrentUsers"] = System.Convert.ToInt32(Application["CurrentUsers"]) + 1;
            Application.UnLock();
        }
        void Session_OnEnd(object Sender, EventArgs E)
        {
            Application.Lock();
            Application["CurrentUsers"] = System.Convert.ToInt32(Application["CurrentUsers"]) - 1;
            Application.UnLock();
        }

2.In Aspx Page

<%=Application["CurrentUsers"].ToString()%>

In web.config timeout will be make 10, by default 20

Friday, 21 March 2014

hex code for checkbox and apply to css

HEX Code for check box is :
                         Checked :2610,
                    Un Checked :2611.

In Css
.checked:before
{
    content:"\2611";
    }
in Aspx page or html page or View

<a href="#" class="checked"></a>