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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Some SERIOUS DBase help

Status
Not open for further replies.

cyprus106

Programmer
Apr 30, 2001
654
I've been working with the Data Access components in Builder and toying with Microsoft Access databases and tables and showing the fields, etc... I was just beginning to think I almost had the hang of it and I remember there's the Borland Examples. When I looked at them I got 10x more confused. I seriously need some decent tutorials on this stuff. I've got the database accessed and I can show it on a DBGrid so I don't need to know how to set all of that up, (hint: I don't need that FAQ on setting up a database) what I need to know is more along the lines of examples of using the functions, how I can manipulate data, etc... I've got some problems with programatically moving to a record in the table, doing finds on the record(s), making new records, accessing individual records. All of the little things that I'm sure there's functions for and just when I think I've found them I check the BCB Help file and it's not what I need at all. Or sometimes I just don't know how to use them and can't figure it out. Normally I would just use the help file but it's not really helping me. And their examples, not to mention word phrasing, leave something to be desired.

I hope somebody can help me out here.
Thanks a lot, Cyprus
 
ill send you a program i did for school. theres everything you can do with a database in builder just tell me your email
Query1->Sql->Add("insert into table1(name,firstname)");
Query1->Sql->Add("Values:)Name1,FirstName1)");
Query1->Params->Items[0]->AsString = Name1->Text;
Query1->Params->Items[1]->AsString = FirstName1->Text;

thats one way to do request nyway take my prog its open source! :D
 
I have had some dificulty with the fieldvalues property
so I tend to stick with the fields [] property.

this puts you on the 10th record.
Table1->RecNo = 10;

Table1->Edit(); // edit field
Table1->Fields->Fields[2]->AsString = s1;
Table1->Fields->Fields[3]->AsBoolean = false;
Table1->Post ();

Table1->Close ();
Table1->ReadOnly = true;
Table1->Open ();

Table1->Active = false;
Table1->EmptyTable ();
Table1->Active = true;

Table2->Close ();
Table2->CreateTable ();
Table2->Open ();

Table2->Append(); //new field
Table2->Fields [0] = Table1->Fields [1];
Table2->Fields [1] = Table1->Fields [3];
Table2->Fields [2] = Table1->Fields [4];
Table2->Post ();

char buff1 [256];
strcpy (buff1, Table1->Fields[4]->AsString.c_str ());

int z = z + Table1->Fields[2]->AsFloat;

{
if (FileExists ("descript.dbf"))
{
//Clear the items from design time, default.
DBComboBox1->Items->Clear ();

Table4->Open ();
Table4->First ();
while (!Table4->Eof)
{
DBComboBox1->Items->Add (Table4->Fields[0]->AsString);
Table4->Next ();
}
DBComboBox1->ItemIndex = -1;
Table4->Close ();
}
}

Its easy once you know the secret. and the secret sometimes is interpreting the function parameters.
 
OK that helps a lot... Most of that solved most of my problems. But now how do I do something like select an entry in the DB list box (DBBusinessCombo) and make a few of the fields in its row appear under a few of the corresponding Edit Boxes? Cyprus
 
DBEdit boxes have a property called field.
this links the text in this component to the
corresponding field in the selected record.
when you select a record by way of a list box
or other method the text for each field is
displayed. provided you have set up a separate
DBEdit for each field. The Datasource property
also must be set to the datasource of the table.
 
I know that much. I can show data in the edit boxes... let me elaborate.

I set up a DBComboBox and it takes all of the data in the first column of my table ('LOCATION NAME'). I tried to set it up so that when a user selects one of the values in the DBCombo, the 3 DBEdit boxes ('LOCATION CITY', 'LOCATION ADDRESS', and 'LOCATION STATE') that I had would change, corresponding to the values in that particular row. When I try to do this the edit boxes to update but the values in them are always the same. They always only show the first row's data.

For example:
if my first row in my table was:
FairCom | 2100 Forum blvd. | Winchestertonfieldville | Missouri
and my second row was:
MyBusiness | 1400 AM Radio | whocaresville | Montana

My DBComboBox would then show both FairCom and MyBusiness. When I select FairCom the right data appears in the edit boxes but when I select MyBusiness the data in the edit boxes stays the FairCom data.

I don't know enough about the database programming yet to know what's going on but I've been stuck on this issue for a week and a half and that was my biggest problem regarding the database stuff.

Thanks, Cyprus
 
I would think that you are iterating through the
database file and grabbing the text from the desired
field and inserting this into the combobox.

Use a TListBox not a TDBComboBox. You dont need the
Database aware stuff for the listbox.
Then you could get the Itemindex of the list box and
do

table1->RecNo = ListBox->ItemIndex;

You may have to adjust the itemindex.
as
table1->RecNo = ListBox->ItemIndex + 1;
or
table1->RecNo = ListBox->ItemIndex - 1;

I Cant remember which offhand.
 
ok, I'll say Table1->RecNo = ListBox1->ItemIndex; and the RecNo doesn't change. It's always -1. Help?? Cyprus
 
This works for me;

Questions??

void __fastcall TForm1::FormCreate(TObject *Sender)
{
try
{
if (!FileExists ("test.db"))
{
Application->MessageBox(" A new database will now be created.", "New Data File", MB_OK);
Table1->CreateTable ();
Table1->Open ();

Table1->Append ();
Table1->Fields->Fields [0]->AsString = "feild1->record1";
Table1->Fields->Fields [1]->AsString = "feild2->record1";
Table1->Fields->Fields [2]->AsString = "feild3->record1";
Table1->Post ();

Table1->Append ();
Table1->Fields->Fields [0]->AsString = "feild1->record2";
Table1->Fields->Fields [1]->AsString = "feild2->record2";
Table1->Fields->Fields [2]->AsString = "feild3->record2";
Table1->Post ();

Table1->Append ();
Table1->Fields->Fields [0]->AsString = "feild1->record3";
Table1->Fields->Fields [1]->AsString = "feild2->record3";
Table1->Fields->Fields [2]->AsString = "feild3->record3";
Table1->Post ();
}
else
Table1->Open ();
}
catch (...)
{

}

int x = Table1->RecordCount;

for (int y = 0; y < x; y++)
{
Table1->RecNo = y + 1;
ComboBox1->Items->Add (Table1->Fields->Fields [0]->AsString);
}
ComboBox1->ItemIndex = 0;
}

void __fastcall TForm1::ComboBox1Click(TObject *Sender)
{
Table1->RecNo = ComboBox1->ItemIndex + 1;
}

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top