Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How to dispose a DataSet
Message
 
To
08/05/2005 22:01:33
General information
Forum:
ASP.NET
Category:
ADO.NET
Miscellaneous
Thread ID:
01012057
Message ID:
01012141
Views:
26
Mike,
How do you close the dialog form? Do you have a button with dialogresult set to OK on the form?
Try the following code based on your code:
private void button1_Click(object sender, System.EventArgs e)
{
     frmDialog frmDiag = new frmDialog()
     frmDiag.ShowDialog();
     frmDiag.Dispose(); // always dispose of the form
}


public frmDialog()
{
   string strConn = "Password=ga;Persist Security Info=True;User    ID=sa;Initial Catalog=Northwind;Data Source=MICHAEL";
   string strSql = "Select * from mySampTable";
   SqlConnection cn = new SqlConnection(strConn);
   SqlDataAdapter da = new SqlDataAdapter(strSql,cn);
   DataSet ds = new DataSet();
   da.Fill(ds);
   this.dataGrid2.DataSource = ds.Tables[0];

   //cn.Close(); // you shouldn't have to do this the Fill method should both open and close the connection
   cn.Dispose();
}
I don't know if the changes will solve your problem but it is worth a try. Also maybe try to make ds a form member.

Einar
Semper ubi sub ubi.
Previous
Reply
Map
View

Click here to load this message in the networking platform