PDA

Click to See Complete Forum and Search --> : Reseting database


xstopx81
Aug 10th, 2000, 03:47 PM
I have a database in my prog. If an user chooses to search the people who lives in certain state, only the people will show up on dbgrid who lives in that state. The problem is I dont know how to restart. I mean I dont know how to reset the database so that the user can start fresh.

One other thing, I would also like for the user to add to the searched lists. For example, if they choose to I would like for them to pick two or more items, so that they can search CA, and then search for VA and the list for VA people will add on to CA people.

[Edited by xstopx81 on 08-10-2000 at 05:25 PM]

Paul Warren
Aug 11th, 2000, 04:51 AM
How are you trying to do this ? Have you got a databound control or are you doing things manually ? Do you filter using the select statement or is it with the filter property of the control ?

If you give me the info. I'll see if I can help.

xstopx81
Aug 11th, 2000, 12:29 PM
ok Paul here's how it goes. I filter my database using select statement and I am trying to do this manually for now but if there's any other method I can use, I'll certainly try them. Thanks for replying and hope to hear from you soon

Paul Warren
Aug 14th, 2000, 03:26 AM
This is MSDN has to say about rebinding the datasource, which is what you need to do.

Changing the RecordSource of the DataSource
The most common method of changing displayed data is to alter the query of the DataSource. For example, if the DataGrid control uses an ADO Data control as its DataSource, rewriting the RecordSource and refreshing the ADO Data control will change the data displayed.

' The ADO Data control is connected to the Northwind database's
' Products table. The new query asks for all records which have
' the SupplierID = 12.
Dim strQuery As String
strQuery = "SELECT * FROM Suppliers WHERE SupplierID = 12"
Adodc1.RecordSource = strQuery
Adodc1.Refresh

Changing the DataSource
At run-time you can reset the DataSource property to a different data source. For example, you may have several ADO Data controls, each connected to different databases, or set to different RecordSource properties. Simply reset the DataSource from one ADO Data control to another:

' Reset the DataSource to an ADO Data control that is connected to
' the Pubs database, using the Authors table.
Set DataGrid1.DataSource = adoPubsAuthors

Rebind the DataSource
When using the DataGrid control with a remote database such as SQLServer, it's possible that the structure of the table may become altered. For example, a field may be added to the table. In that case, you can invoke the Rebind method to recreate the grid from the new structure. Note that if you have altered the columns' layout of the grid at design-time, the DataGrid control will attempt to recreate the current layout, including any empty columns. You can, however, force the grid to reset all columns by first invoking the ClearFields method.

Let me know if you need any more help with this.

eXodus842
Aug 19th, 2000, 10:12 AM
Hey Guys, I'm having exactly the same problem, I'm new to databases and I don't know if I'm doing this the right way, but I have a 2 ADO controls on my form and a Datagrid, and when it loads, the datagrid gets it's info from the first ADO control, and I have it so that when someone searches for a name in the database, it sets the recordsource of the other ADO command with an SQL query containing the name of the person to search for, and switches the datagrid to that and updates it, all fine, that works great. But I can't seem to get it to reset. I know I'm probably doing this all wrong so any help would be gratefully recieved. eX

VB 6 SP3

[Edited by eXodus842 on 08-19-2000 at 12:25 PM]

shippyatdrexel
Aug 22nd, 2000, 03:40 PM
This worked for me guys. I have a form that adds records to the database, and another that displays the DataGrid. I needed the grid to refresh each time I added a record. Here's my code:

Adodc1.Refresh
Set Datagrid1.DataSource = Adodc1

And I put it in my Form_Activate event to refresh it each time the form was shown.