Monday, November 30, 2009

Check Duplicate Row while working with CSV file

Hi All,

If you are working with CSV file parsing, there is always a good practice to check duplicate rows while parsing data. If prevents the system crashing due to duplicate record entry in data and we could make proper exception handling with Friendly message to our users.

So, here i have make one usable function with help of C# as code language.

435 private int CheckDuplicateRows(string _SaveLocation)

436 {

437 if (!string.IsNullOrEmpty(_SaveLocation))

438 {

439 string[] FileContent = File.ReadAllLines(_SaveLocation);

440 ArrayList al = new ArrayList();

441 int lineNo = 1;

442 //ignore the header row

443 for (int i = 1; i <= FileContent.Length - 1; i++)

444 {

445 lineNo += 1;

446 if (al.Contains(FileContent[i]))

447 {

448 return lineNo;

449 }

450 else

451 {

452 al.Add(FileContent[i]);

453 }

454 }

455 return 1;

456 }

457 else return 1;

458 }


Thats all, and your code is safe to manage the exception of DuplicateRow, it will return 1 if there is no duplicate row else will return the duplicate row number.

Happy Coding :)

Find any Objects you have created in MS-SQL Server

Hi All,

before couple of hours i was looking for one of my user defined function, the misery is i forget its name( ... lazy developer habit), here is solution to my laziness.

SELECT name, id, xtype, uid, info, status, base_schema_ver, replinfo, parent_obj, crdate, ftcatid, schema_ver, stats_schema_ver, type, userstat, sysstat, indexdel, refdate,version, deltrig, instrig, updtrig, seltrig, category, cache
FROM sys.sysobjects

XTYPE =
‘U’ For table
‘PK’ For Primary Keys
‘F’ For Foreight Keys
‘V’ For views
‘P’ For stored procedures
‘TR’ For triggers
‘S’ For system objects
‘FN’ Function

It searches for all database objects.