Monday, February 29, 2016

How to change a value of a DataItem in a GridViews RowDataBound Event

if (e.Row.RowType == DataControlRowType.DataRow)
{
 DataRow row = ((DataRowView)e.Row.DataItem).Row;
 for (int i = 0; i < row.ItemArray.Length; i++)
 {
  var obj = row.ItemArray[i];
  if (obj.GetType().Name == "DateTime")
  {
   e.Row.Cells[i + 1].Text = ((DateTime)obj).ToShortDateString();
  }
  else if (obj.GetType().Name == "Boolean")
  {
   e.Row.Cells[i + 1].Text = ((Boolean)obj).ToYesNo();
  }
 }
}

jQuery: get the file name selected from

$('input[type=file]')[0].files[0].name;

$("input[type=file]")[0].files[0].type;

$("input[type=file]")[0].files[0].size;

Wednesday, February 24, 2016

How do you check if a certain index exists in a sql server table?

IF EXISTS(SELECT * FROM sys.indexes WHERE name='[IndexName]' AND object_id = OBJECT_ID('[Schema].[Table]'))
BEGIN
    --statements
END

Tuesday, February 23, 2016

Sunday, February 21, 2016

How to disable all triggers MS SQL Server

To disable all trigger

sp_msforeachtable 'ALTER TABLE ? DISABLE TRIGGER all'

Or to enable or triggers

sp_msforeachtable 'ALTER TABLE ? ENABLE TRIGGER all'

Enable / Disable trigger in MS SQL server

DISABLE

ALTER TABLE table_name DISABLE TRIGGER tr_name

ENABLE

ALTER TABLE table_name ENABLE TRIGGER tr_name

SQL Server: Database stuck in “Restoring” state

RESTORE DATABASE MyDatabase
FROM DISK = 'MyDatabase.bak'
WITH REPLACE,RECOVERY