Com Exception is unhandeled while executing ExecuteReader
hi
i get following exception when i execute my code
"COM object that has been separated from its underlying RCW cannot be used."
code is as follow:
private
string conString;OleDbDataReader
dr;OleDbDataAdapter da;OleDbConnection con =newOleDbConnection();OleDbCommand com =newOleDbCommand();OleDbParameter id =newOleDbParameter();OleDbParameter name =newOleDbParameter();public
bool IsCompanyExist(string namee){
bool exist =false;strOleDb =
"Select strCompanyName from tblCompanyMain where strCompanyName = @strCompanyName";this.com.CommandText = strOleDb;this.con.ConnectionString =this.conString;this.com.Connection = con;this.name.ParameterName ="@strCompanyName";this.name.Value = namee;com.Parameters.Add(name);
try{
con.Open();
dr = com.ExecuteReader();<<<<< Here errror occurs
if (dr.Read()){
exist =
true;}
else{
exist =
false;}
con.Close();
dr.Close();
com.Parameters.Clear();
}
catch (OleDbException ex){
string s = ex.Message ;}
return exist;}
publicint GetCompanyID(string namee){
int id = 0;strOleDb =
"Select intID from tblCompanyMain where strCompanyName = @strCompanyName";com.CommandText = strOleDb;
con.ConnectionString = conString;
com.Connection = con;
this.name.ParameterName ="@strCompanyName";this.name.Value = namee;com.Parameters.Add(
this.name);try{
con.Open();
dr = com.ExecuteReader();<<<<<Here error comes
if (dr.Read()){
id = dr.GetInt32(0);
}
}
catch (OleDbException ex){
string s = ex.Message;}
con.Close();
dr.Close();
com.Parameters.Clear();
return id;}
First time when this code executes it works fine...but second time when i hit the button to search the company it gives the exception....kindly can any one help mee

