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!

Stroring Strings of StringGrid in database field 1

Status
Not open for further replies.

jackrabbithanna

Programmer
Aug 19, 2004
11
0
0
US
I'm creating a program to manage a database of invoices. Each invoice will have a parts list. The parts list has part number,price, quantity etc... I'm using a string grid to display and edit this data. The problem is how to store the strings in a single binary field in a paradox table. I've been playing with TBlobStreams and other streams but I can't get it right. I don't even know if its possible to store an array of strings in a single field. Any pointers or strategies would be appreciated. Here's the (unworkable) code I got so far: It compiles but gives an StreamError exception when executed

TMemoryStream *pns = new TMemoryStream;
TStream *pndatas ;
pndatas=dataMod->Invoice->CreateBlobStream(dataMod->Invoice->FieldByName("PartsList"),bmReadWrite);

lbPartNumber->Items->SaveToStream(pns);
pndatas->CopyFrom(pns,pns->Size);

delete pns;
delete pndatas;

dataMod->Invoice->Post();

 
I don't know why you are using the MemoryStream, so I'm going to try help you without the stream ok?

You said all the invoice information is in the StringGrid so you can use the TStringList class, where every string is the corresponding column in your Grid. I'm going to suppose that every row is a record.

You said too that you have the Paradox table, I suppose that it contains a BlobField.

So the first step is to pass the data from the grid to the StringGrid.

Like this:
Code:
TStringGrid *InvoiceData;
InvoiceData = new TStringGrid ();
//NUMBER_OF_ATTRIBUTES_IN_INVOICE can be the number of columns in your grid - 1
//NUMBER_OF_RECORDS can be number of rows in your grid - 1
for (int k=0; k<NUMBER_OF_RECORDS; k++)
{
   for (int i=0; i<NUMBER_OF_ATTRIBUTES_IN_INVOICE; i++)
   {
      InvoiceData->Append (StringGrid->Cells[i][k])
   }
/*   Every time the App comes until this point the StringList has the data of one record, so now we need to save it, and clear the StringList*/
   Table->Insert();
   Table->FieldByName ("PartsList")->Value = InvoiceData;
   Table->Post();
   InvoiceData->Clear();
}
delete InvoiceData;

--- LastCyborg ---
 
Thanks for your interest and help. Here's what I got now

Actually the invoice information is in the paradox table. I'm trying to store a list of parts,prices,and quantities in one field inside the table. The table has many other fields with single pieces of information.

Do know what I'm missing?

TStream *partnums = dataMod->Invoice->CreateBlobStream(dataMod->Invoice->FieldByName("PartsList"),bmReadWrite);
TStream *partnames = dataMod->Invoice->CreateBlobStream(dataMod->Invoice->FieldByName("PartsNamesList"),bmReadWrite);
TStream *partprices = dataMod->Invoice->CreateBlobStream(dataMod->Invoice->FieldByName("PartsPriceList"),bmReadWrite);
TStream *partquantitys = dataMod->Invoice->CreateBlobStream(dataMod->Invoice->FieldByName("PartQuantityList"),bmReadWrite);
lbPartNumber->Items->SaveToStream(partnums);
lbName->Items->SaveToStream(partnames);
lbPrice->Items->SaveToStream(partprices);
lbQuantity->Items->SaveToStream(partquantitys);
dataMod->Invoice->Post();

This works and each list of strings is stored in one field. Retrieving the data is similar but I still get an error here's the code

/*
TStream *partnums = dataMod->Invoice->CreateBlobStream(dataMod->Invoice->FieldByName("PartsList"),bmRead);
TStream *partnames = dataMod->Invoice->CreateBlobStream(dataMod->Invoice->FieldByName("PartsNamesList"),bmRead);
TStream *partprices = dataMod->Invoice->CreateBlobStream(dataMod->Invoice->FieldByName("PartsPriceList"),bmRead);
TStream *partquantitys = dataMod->Invoice->CreateBlobStream(dataMod->Invoice->FieldByName("PartQuantityList"),bmRead);
lbPartNumber->Items->Clear();
lbPartNumber->Items->LoadFromStream(partnums);

Error right here !!!!
EDBEngineError with message can't open blob field;
I think the strings are there because if I step over the the other three lists are populated without error. Strange...


lbName->Items->Clear();
lbName->Items->LoadFromStream(partnames);
lbPrice->Items->Clear();
lbPrice->Items->LoadFromStream(partprices);
lbQuantity->Items->Clear();
lbQuantity->Items->LoadFromStream(partquantitys); */
 
I understand what you want to do, but I think you are taking a difficult way for doing that. If I'd to do that I'll do it as I said before. The problem is I have never worked the streams and the DB's as you do.



--- LastCyborg ---
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top