Friday, 29 July 2011

To display Month name instead of Month number in SQL Server

-- Consider following statement 
SELECT DATENAME(m, str(Month_Number) + '/1/2011')
-- for eg:
SELECT Year, DATENAME(m, Month + '/1/2011') AS Month,from calendar

-- Here m will be the output value
-- str(Month_Number) function convert month number to string i.e 2 => "2"
-- finally whole string "02/1/2011" is passed as argument

Tuesday, 26 July 2011

To get List of Triggers in SQL Server


SELECT trigger_name = sysobjects.name,
trigger_owner = USER_NAME(sysobjects.uid),
table_schema = s.name,
table_name = OBJECT_NAME(parent_obj),
isupdate = OBJECTPROPERTY( id, 'ExecIsUpdateTrigger'),
isdelete = OBJECTPROPERTY( id, 'ExecIsDeleteTrigger'),
isinsert = OBJECTPROPERTY( id, 'ExecIsInsertTrigger'),
isafter = OBJECTPROPERTY( id, 'ExecIsAfterTrigger'),
isinsteadof = OBJECTPROPERTY( id, 'ExecIsInsteadOfTrigger'), [disabled] = OBJECTPROPERTY(id, 'ExecIsTriggerDisabled')
FROM sysobjects INNER JOIN sysusers ON
sysobjects.uid = sysusers.uid
INNER JOIN sys.tables t ON sysobjects.parent_obj = t.object_id
INNER JOIN sys.schemas s ON t.schema_id = s.schema_id
WHERE sysobjects.type = 'TR'

Thursday, 23 June 2011

How to use Check Box in Gridview in Asp.Net

ASP.net with C#
Take a GridView, Connect it to a table.

  •  Go to the 'Edit-Columns' of the GridView. 
  •  Add a 'template-field' 
  •  Hit OK. 
  •  Now, go to the 'Edit-Template' of the GridView. 
  •  In the 'Column[0]' of the Item-Template, drag-drop a CheckBox 
  •  Check out whats the ID of the CheckBox (must be CheckBox1) 
  •  That's it. 

Now Stop 'Editing Template' In the Code-Behind use the following code :

// Add Button code
//GridView1 is Gridview control ..
protected void buttonAdd_Click(object sender, EventArgs e)
{
  // Iterating through Gridview rows
  foreach (GridViewRow gvr in GridView1.Rows)
  {
    // Finding checkbox in a row of data grid control
    CheckBox cb = (CheckBox)gvr.FindControl("CheckOne");
    if (cb.Checked == true)
    {
      // Action to be taken if check box is checked
      Response.Write("<h1>Checked !!</h1>");
    }
  }
}