January 31, 2012

Round to nearest Whole no in Sql

Select cast(  Round(10.75 , 0)  as  decimal(10,0))


rounding of numeric no can be done by round function , it takes input numeric number.








Add You comment below

January 27, 2012

SSRS Expression Left , MonthName from parameter

 Left(  MonthName(Month(CDate(Parameters!ToDate.Value))), 3) & " "  &  Year(CDate(Parameters!ToDate.Value))
















Add You comment or questions so that i will add new post or reply to your questions

January 24, 2012

Initialize values to string array

We can initialize the values to string array to null before assigning the values.
Use following code:



string[] users = null;
string[] roles = null;



for (int i = 0; i < RolesListBox.Items.Count; i++)

{
    //assing the length of array using this code
    roles = new string[RolesListBox.Items.Count]
    if (RolesListBox.Items[i].Selected == true)
     roles[i]= RolesListBox.SelectedItem.Text;
}


January 20, 2012

GridView with fixed Headers


<style type="text/css">
  .header
  {
    font-weight:bold;
    position:absolute;
    background-color:White;
  }
  </style>


Add this style sheet in your page





<asp:GridView ID="GridView1" runat="server" Height="143px" Width="600px" 
                       HeaderStyle-CssClass ="header">


Register assembly in GAC


Register assembly in GAC

in command prompt of visual studio 2010 / 2008/ 2005

type this command

gacutil  /?

shows the all commands

gacutil /i <assembly name>  name of assembly to register.

path consist of full path.

January 15, 2012

Enum For Months .Net


#region Calender Constantspublic enum CalMonths{
January = 1,
Februray,
March,
April,
May,
June,
July,
August,
September,
October,
November,
December
}#endregion



public void BindDropdownlist()foreach (int value in Enum.GetValues(typeof (CalMonths)))new ListItem(Enum.GetName(typeof(CalMonths), value), value.ToString()));Convert.ToString(DateTime.Now.Month);
{

{
ddlMonth.Items.Add(
}
ddlMonth.DataBind();
ddlMonth.SelectedItem.Value =
GetYear();
}

Code to get last 3 Years

public void GetYear()int year = DateTime.Now.Year;int text;//MD: for (int i = -1; i <= 1; i++)
{
text = year + (i);

list.Text =

list.Text = list.Text; for (int i = -1; i <= 1; i++)ListItem list = new ListItem();Convert.ToString(text);int y = Convert.ToInt32(list.Text.Trim()) + 1;//+ "-" + y.ToString().Substring(2, 2);list.Value =
ddlYear.Items.Add(list);
}
ddlYear.SelectedValue =
}
Convert.ToString(text);Convert.ToString( DateTime.Now.Year);

{



Find SeverName Database name


select @@Servername


select db_Name()

January 6, 2012

Find Records not in another table


SELECT * FROM   CallLEFT OUTER JOIN Phone_Book
  ON (Call.phone_number = Phone_book.phone_number)
  WHERE Phone_book.phone_number IS NULL

January 4, 2012

Error Handling in SQL


Declare @Error int


set @Error = @@ERROR                    

                if @Error = 0
set @Error = @@ERROR


IF @Error = 0
BEGIN
COMMIT  tran
END  
ELSE
BEGIN
ROLLBACK tran
END