Sunday, November 2, 2008

This row already belongs to another table , C# exception

//Here the scenario

DataSet dsSoruce = new DataSet();
DataSet ds1 = new DataSet();
DataTable dt1 = new DataTable("SelectedData");
DataRow[] dr1 = null;
string strExpr = string.Empty;


strExpr = "Name Like 'H%' "
// here we are doing copy into local dataset
ds1 = dsSoruce.Copy();
//copy talbe into local table
dt1 = ds1.Tables[0];
// get selected rows

dr1 = dt1.Select(strExpr);

if ((dr1 != null) && (dr1.Length > 0))
{
//clear the main dataset table
dsSoruce.Tables[0].Clear();
//import the row into main dataset
foreach (DataRow dr in dr1)
{
dsSoruce.ImportRow(dr);
}
}

System.Exception: System.Data.OracleClient requires Oracle client software version 8.1.7 or greater

Solution:

go to :-
C:\Oracle\product\10.1.0\Client_2 folder

follow the below steps:
1) right click on this folder
2) go to properties
3) select "administrator"
4) remove 'Read & Executes' permission
5) again add 'Read & Executes' permission on this folder

there you go...

.Net- ordered Hashtable

.Net 2.0 introduce "OrderedDictionary" in order to store sorted (key,object) pair value.

Here is the sample code in [C#]

using System.Collections.Specialized;

OrderedDictionary objOrderedDictionary = new OrderedDictionary();

objOrderedDictionary.Add("1", "first value");
objOrderedDictionary.Add("5", "second value");
objOrderedDictionary.Add("8", "third value");
objOrderedDictionary.Add("12", "fourth value");

//set enumerator
IDictionaryEnumerator enumerator;
enumerator = odServiceAmount.GetEnumerator();
while (enumerator.MoveNext())
{
string sKey = enumerator.Key.ToString().Trim();
string sValue = enumerator.Value.ToString().Trim();
}

Query to find duplicate record in SQL server table & store into table

1) Simple query to find duplicate records in SQL server

select a,count(1)
from #temp
group by a
having count(1) > 1
order by count(1) desc

2) Dump the duplicate records into SQL table
create table #temp (a varchar(15),b varchar(15),c int)
insert into #temp
select emp_no,emp_name,count(1)
from employee
group by emp_no,emp_name
having count(1) > 1



drop table #temp