I have a class like this:
class connect:IDisposable
{
public void OpenChannel(SqlConnection ch)
{
ch.ConnectionString=".....";
ch.Open();
}
public void Dispose()
{
}
}
And another class like this:
public Cust
{
SqlConnection channel=new SqlConnection();
SqlCommand command=new SqlCommand();
public void Method()
{
using(connect con=new connect())
{
con.OpenChannel(channel);
command.connection=channel;
.....
....
....
command.ExecuteNonQuery();
}
}
But when I run ExcuteNotQuery() there is an error: “no open connection”
So what is wrong?
1 Answer