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 = new OleDbConnection();
OleDbCommand com = new OleDbCommand();
OleDbParameter id = new OleDbParameter();
OleDbParameter name = new OleDbParameter();
public bool IsCompanyExist(string namee)
{
bool exist = false;
strOleDb =
;
this.com.CommandText = strOleDb;
this.con.ConnectionString = this.conString;
this.com.Connection = con;
this.name.ParameterName =
;
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;
}
public int GetCompanyID(string namee)
{
int id = 0;
strOleDb =
;
com.CommandText = strOleDb;
con.ConnectionString = conString;
com.Connection = con;
this.name.ParameterName =
;
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
.NET Development31
|