Monday, July 21, 2014

Sort in DataTable in C#



  DataView dv = dt.DefaultView;
            dv.Sort = "Date asc";
            DataTable sortedDT = dv.ToTable();

Thursday, June 19, 2014

Drop FOREIGN KEY constraint from all table of database

while(exists(select 1 from INFORMATION_SCHEMA.TABLE_CONSTRAINTS where CONSTRAINT_TYPE='FOREIGN KEY'))
begin
       declare @sql nvarchar(2000)
       SELECT TOP 1 @sql=('ALTER TABLE ' + TABLE_SCHEMA + '.[' + TABLE_NAME
       + '] DROP CONSTRAINT [' + CONSTRAINT_NAME + ']')
       FROM information_schema.table_constraints
       WHERE CONSTRAINT_TYPE = 'FOREIGN KEY'
       exec (@sql)
end