Sunday, August 29, 2010

Remove the Duplicate Rows in DataTable

Removing the Duplicate Rows in DataTable in C# is simple.

Best way is use DISTINCT Keyword in Database Query, but some times we may fill the data manually.

We can remove by using two type

First One is very simple and it is used when we need to compare all columns in the rows.
DataTable _NewTable=_Table.DefaultView.ToTable(true);
Second, Suppose we need to remove the rows for specific columns only means then we can go for the following Method
List<string> keyColumns = new List<string>();
keyColumns.Add("Column1");
keyColumns.Add("Column2");
RemoveDuplicatesFromDataTable(ref _Table, keyColumns);

public void RemoveDuplicatesFromDataTable(ref DataTable table, List<string> keyColumns)

{
Dictionary<string, string> uniquenessDict = new Dictionary<string, string>(table.Rows.Count);
StringBuilder stringBuilder = null;
int rowIndex = 0;
DataRow row;
DataRowCollection rows = table.Rows;
while (rowIndex < rows.Count - 1)
{
row = rows[rowIndex];
stringBuilder = new StringBuilder();
foreach (string colname in keyColumns)
{
stringBuilder.Append(((string)row[colname]));
}
if (uniquenessDict.ContainsKey(stringBuilder.ToString()))
{
rows.Remove(row);
}
else
{
uniquenessDict.Add(stringBuilder.ToString(), string.Empty);
rowIndex++;
}
}
}



Tuesday, August 24, 2010

Disabling the selection in UITableView.

To disable the selection in UITableView use the following code
cell.selectionStyle = UITableViewCellSelectionStyleNone;
or


[cell setSelectionStyle:UITableViewCellSelectionStyleNone];

Sunday, August 15, 2010

How to Enabling PHP on Mac Leopard

To Enable PHP(note: before that enable Apache server)
  1. Open the Terminal.
  2. Type cd /etc/
  3. then type sudo cp php.ini.default php.ini
  4. After that type cd /private/etc/apache2/
  5. uncomment the two modules: php5_module and fastcgi_module. (Remove #). Search for php5_module.
  6. Then Save by ctrl and o
  7. Then reload the Apache server

Tuesday, August 10, 2010

Setting Background image or color for UITableView in IPhone

Hi,
Now, we are going to see how to set the background color or image for UITableView.
To set the Background color or image for UITableView set the background for parentview of the tableview and set the background color as clearcolor this shows the transparent color to so the parentview background.

The following code is for setting background image for tableview 

self.parentViewController.view.backgroundColor=[UIColor colorWithPatternImage:[UIImage imageNamed:@"tvbg.png"]];
self.tableView.separatorColor=[UIColor clearColor];
self.tableView.backgroundColor=[UIColor clearColor];