PDA

Click to See Complete Forum and Search --> : Database Un-binding?


MattG
Jan 14th, 2000, 11:34 AM
In a large app the main database gets deleted and then replaced with another. For this to happen the app needs to disconnect from the DB. With a DataControl this is easy with .DatabaseName = "". But I have a DBGrid attached to the DataControl and now no matter what I try the DB always reports that it is in use, and therefore can not be deleted. Is there a Property of the DBGRid that will release the DB??? Or is there another approach? Who said VB was simple?

netSurfer
Jan 14th, 2000, 11:38 AM
can't you just set the DataMode to 1? 0 = bound, 1 = unbound. I don't use databound controls, I prefer to handle it myself so I don't know if it would work.

MattG
Jan 14th, 2000, 11:43 AM
No... DataMode is Design time only (rats).

netSurfer
Jan 14th, 2000, 11:46 AM
ok, can you clear the database it's bound to? I'm not familiar with the control. I'm at work right now but if no one has come up with an answer by the time I go home, I'll try it and see what I can find out.

Aaron Young
Jan 14th, 2000, 11:54 AM
Clearing the Database Name isn't enough, you need to actually Close the Database, try this:

Private Sub cmdRemove_Click()
'Disconnect from the DB and Delete It
Data1.Recordset.Close
Data1.Database.Close
DBGrid1.ReBind
Kill$ "C:\Files\db.mdb"
End Sub

Private Sub cmdConnect_Click()
'Create a New Copy of the DB and ReConnect to it.
FileCopy "C:\Files\db1.mdb", "C:\Files\db.mdb"
Data1.DatabaseName = "C:\Files\db.mdb"
Data1.Refresh
DBGrid1.ReBind
End Sub



------------------
Aaron Young
Analyst Programmer
aarony@redwingsoftware.com
ajyoung@pressenter.com