Pages

Thursday, 4 August 2011

Displaying Festival Names on Calendar control in ASP.Net

0 comments
 
Tags : Festival Names,Calendar Control,Importance of the day,Asp.Net,C#.Net,SQL Server.

Hi Friends,In this article i would like to explain how to display Festival Names on Calender control in ASP.Net.


* For this i took 1 Calendar control on to the page.

* I created a table with name(Holidays) in SQL Server 2005 & fields are HolidayName,HolidayDate.

* Please find the below table once :



* Then find the code for Calender_DayRender event :

Source Code :

Default.aspx.cs :
using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
public partial class _Default : System.Web.UI.Page
{
SqlConnection con;
protected void Page_Load(object sender, EventArgs e)
{
con = new SqlConnection(ConfigurationManager.ConnectionStrings["DotnetGuruConnectionString"].ConnectionString);
}
protected void Calendar1_DayRender(object sender, DayRenderEventArgs e)
{
CalendarDay day = (CalendarDay)e.Day;
SqlCommand cmd = new SqlCommand("select HolidayName,HolidayDate from Holidays", con);
con.Open();
SqlDataReader dr = cmd.ExecuteReader();

while (dr.Read())
{
if (day.Date.ToString() == dr["HolidayDate"].ToString())
{
TableCell cell = (TableCell)e.Cell;
string s1 = dr["HolidayName"].ToString();
if (s1 != null)
{
cell.BackColor = System.Drawing.Color.LightGray;
cell.Controls.Add(new LiteralControl("
" + s1));
}

}

}
con.Close();
}
}
Design View :

Default.aspx :


 















* Then finally Build(F6) your application & run the application by pressing(F5) button.

* Your out put will looks like as below :
Thank You...

Readmore...
Tuesday, 2 August 2011

Logical Operators in SQL Server.

0 comments
 
Tags : Logical Operators,Sql Server 2005,Sql Server 2008,Sql Server Operators.

Hi Friends,In this article i would like to explain Logical Operators in SQL Server.

* Logical operators, like comparison operators, return a Boolean data type with a value of TRUE, FALSE, or UNKNOWN.

* Available Logical Operators :


1) AND:

Performs a logical AND operation. The expression evaluates to TRUE if all conditions are TRUE.

Example :

SELECT * FROM Class
WHERE ( Marks > 40 AND Marks < 100)


2) OR :

Performs a logical OR operation. The expression evaluates to TRUE if atleast one condition is TRUE.

Example :

SELECT * FROM Class
WHERE EmployeeName LIKE 'K%' OR Marks > 40


3) BETWEEN :

It returns TRUE if the operand is within a range otherwise FALSE.

Example :

Select * from Employee
WHERE EmpSalary BETWEEN 5000 AND 15000


4) IN :

This Operator returns TRUE if the operand is equal to one of a list of expressions Otherwise flase.

Example :

SELECT * FROM Students
WHERE StudentId IN(SELECT StudentId FROM CSEDEPT WHERE CSEDeptID=20)


5) EXISTS :

Specifies a subquery to test for the existence of rows.

Example :

SELECT * FROM Students WHERE EXISTS
(
SELECT * FROM Students WHERE CollegeCode='B2'
)


6) LIKE :

Determines whether a specific character string matches a specified pattern.

Example :

SELECT * FROM EnggColleges
WHERE CollegeName LIKE 'S%'

Here,it will return all the records which has 's' as first letter in CollegeName


7) ALL :

It Returns TRUE if all of a set of comparisons are TRUE other wise returns FALSE

Example :

SELECT * FROM Employee
WHERE EMPLOYEEID >= ALL (SELECT EMPLOYEEID from Salary WHERE Salary>5000 )


8) ANY :

ANY returns TRUE when the comparison specified is TRUE for ANY pair, otherwise, returns FALSE.

Example :

SELECT * FROM Colleges WHERE 20000 > ANY
(
SELECT CollegeFess FROM Colleges
)


9) Not :

NOT operator is used To find rows that do not match a value.

Example :

SELECT * FROM Colleges
WHERE CollegeCode NOT IN (50,100,150,200)


Thank You...
Readmore...
Monday, 1 August 2011

Difference between Varchar and NVarchar in SQL Server.

2 comments
 
Tags : Varchar ,NVarchar ,Varchar(n),NVarchar(n),SQL Server,String,Length,Difference.

Hi Friends,in this post i would like to explain difference between Varchar
& NVarchar in SQL Server.

*
The data type Varchar and NVarchar are the sql server data types, both will used to store the string values.

Differences :

1
Character Data Type

Varchar - Non-Unicode Data
NVarchar - Unicode Data

2 Character Size

Varchar - 1 byte
NVarchar - 2 bytes

3 Maximum Length

Varchar
- 8,000 bytes
NVarchar - 4,000 bytes

4 Storage Size

Varchar - Actual Length (in bytes)
NVarchar - 2 times Actual Length (in bytes)


* The abbreviation for Varchar is Variable Length character String.

* The abbreviation of NVarchar is uNicode Variable Length character String.



Thank You...
Readmore...