Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Getting dynamic data.

Status
Not open for further replies.

Hokis

Technical User
May 21, 2007
51
US
Hi,I'm trying to do a simple program, in VB6, which has a button to grab an only .dbf files, i put the CommonDialog in the form to do that, & it's working, I have also a text box which it shows the path of the file name that i grabed.
Now i have another button that supposadly has to manipulate the data & change a column in it, the problem that i don't know how to do that. Do i have to put a ADODC object in the form? But then how am i suppose to attach the table to it, since every time i'm going to browse for a table it is going to be a different .dbf file (table).
Can someone help me.
This is my code so far:

Private Sub cmdBrowse_Click()

dlgCommon.Filter = "Database Files(*.dbf)|*.dbf|All Files(*.*)|*.*"
dlgCommon.ShowOpen
txtFileName.Text = dlgCommon.FileName

End Sub
Thank you,
 
manipulate the data & change a column in it

Manipulate how, and change what? This can be done with the ADO Command object and SQL.

Illegitimi non carborundum.
 
Yes I agree, but how, I need the following: the user will pick a database (.dbf) then click a button & all that button will do is replace a field with another field within that database.
Like in FoxPro, you say (Replace Field1 with Field2 all)
for example, that's what i want to do within VB, with a nice interface, & of course it will get more complicated after that but i have to start somewhere.
So any suggestions?
 
Lets start with the Data Form Wizard...

Start a new standard exe project and in the IDE GoTo the menu item Add-Ins>Add-In Manager
When dialog appears select/highlight VB 6 Data Form Wizard and in the lower right corner put a check in the box next to Loaded/Unloaded in the from labeled Load Behavior>Click OK

Add-Ins>Data Form Wizard.

No Profile>Next>Remote(ODBC)>...

Now here you have a decision to make. You can either use an ODBC DSN or you can go DSN Less which is the prefered method for most when using ADO. Enter the information required.

When you get to the form that asks for the form name, I suggest you use something very descriptive based on the other two options on this form, which are Form Layout and Binding type so if you were to want a single record with ado data control then I would suggest something like formSingleControl or if it was code formSingleCode/formSingleClass and so on.

Run this wizard all 15 times to make sure you have all possibilities/combinations of each type of form with each type of binding.

Save this project for future use and to test any of the forms out just make them as your startup object or use Form1 to make a dialog so you can select which form you want to walk through with F8 to understand more.

You can also use this wizard on access/sql/mysql/oracle and so on and once again I suggest you save these projects for future reference.


On another note...

Normally I would suggest DAO ODBC Direct for access to *.dbf files and for what you would be doing using an ODBC driver setup as a free table directory.

Now back to what you need to do. The above only tells you how to access the data files. What you need to do next is to look up in a SQL reference (MS site should do or VB's help might or if you have access) the Alter Table Statement or perhaps the select into statement.


Good Luck

 
You can programmatically connect different databases to a one datagrid assuming each of your databases has the same structure.
Creat a blank datagrid of a suitable number of colums without any database connections. Add the Column names in Datagrid Properties.

The following will connect an MSAccess .mdb to the grid so you should be able to do the same using the code for .dbf's that you can cut and paste from if you temporarily connect an ADODC control to a dbf.

Code:
Dim LN As New ADODB.Connection  ' Conection tool for Locations
Dim LS As New ADODB.Recordset ' Recordset tool for Locations
LN.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & "C:\DatabaseFolder\MyDatabase.mdb"
LN.CursorLocation = adUseClient
Criteria = "Select * FROM MyTable ORDER BY [MyField]"
LS.Open Criteria, LN, adOpenStatic, adLockOptimistic
Set DataGrid.DataSource = LS
'you can see or edit the data in the table

LS.Close:LN.Close  'when you have finished with the datagrid
 
Hi, Thank u guys for answering my post, I'm trying to do the datagrid fileds, but it doesn't let me add more fields in it, it's just 2 field. So how can i add more fields?
ANd one more question, if the data bases will change (will vary) can i make like 20 fileds, then whatever i'm going to attache it's going to be like 10 fileds only?? will that work, or it has to be exact field numbers & of course names?
Hokis
 

Show the code that you have, tell us what you are getting in your grid, and explain what does not work the way you want.


Have fun.

---- Andy
 
Do you mean add fields at design time or add further rows of data at run time?
If the former. Right click on the grid where you want to add the field, select edit and insert or append.
Quick methoid: If you connect it up to the database using a temporary ADODC control (that you delete after) you can automatically do it using the 'retrieve'.

If the latter:
Refresh the data grid after you have entered each new row otherwise you can get multiple step errors.
Better still, have the datagrid 'addnew' property disabled, have separate text boxes for data entry and use a dynaset to addnew to the records, then refresh the grid to see changes. It is more reliable and less prone to ruining the grid data accidently.

You can still edit cells of the grid.
What you see after refreshing is what the database will be
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top