| Author |
Message |
Clip
Joined: 04 Nov 2003 Posts: 2
|
Posted: Tue Nov 04, 2003 12:19 pm Post subject: Saving Blobs in Sybase DB using DBExpress with Borland C++ B |
|
|
Hello,
I m trying to save a blob into an Sybase DB using DBExpress with the Borland C++ Builder 6.0.
So fare I m using this code:
| Code: |
// var definitions
AnsiString SQL = "select BLOB from TABLE where BLOBX = 1";
const AnsiString BrowserFile = "c:\\temp\\test.pdf";
AnsiString UserName = "Username";
AnsiString Password = "Password";
// Initialize Connections Settings
SQLComponents->SQLConnection->Params->Values["User_Name"] = UserName.c_str();
SQLComponents->SQLConnection->Params->Values["Password"] = Password.c_str();
SQLComponents->SQLClientDataSet->CommandText = SQL.c_str();
// connect / activate
SQLComponents->SQLConnection->Connected = true;
SQLComponents->SQLClientDataSet->Active = true;
// save Blob
SQLComponents->SQLClientDataSet->Append();
TBlobField* blobField = dynamic_cast <TBlobField*> (SQLComponents->SQLClientDataSet->FieldByName("BLOB"));
if (blobField == NULL) return;
blobField->LoadFromFile(BrowserFile);
SQLComponents->SQLClientDataSet->ApplyUpdates(-1);
// disconnect / deactivate
SQLComponents->SQLConnection->Connected = false;
SQLComponents->SQLClientDataSet->Active = false;
|
When calling the method ApplyUpdates() I allways get an error.
Does anybody know what I m doing wrong? Any help would be very nice!
Thank you! |
|
| Back to top |
|
 |
VISOCO Support VISOCO Software Support
Joined: 16 Jul 2002 Posts: 96
|
Posted: Thu Nov 13, 2003 11:24 am Post subject: |
|
|
Hi,
What error do you get?
Best regards. |
|
| Back to top |
|
 |
Clip
Joined: 04 Nov 2003 Posts: 2
|
Posted: Thu Nov 13, 2003 11:50 am Post subject: |
|
|
this is how it works (not exceptionsave!!)
| Code: |
AnsiString SQL1 = "select * from TABLE where BLOBX =";
AnsiString DokuX = Edit1->Text;
const AnsiString BrowserFile = "c:\\temp\\test.pdf";
AnsiString Query1 = SQL1 + DokuX;
AnsiString Query2 = SQL2 + DokuX;
AnsiString UserName = "username";
AnsiString Password = "passwort";
// Hilfsvariablen für Locate()
Variant SearchKey = DokuX;
TLocateOptions Opts;
//Klasse mit benötigten SQL Komponenten
if (SQLComponents == NULL)
{
SQLComponents = new TSQLComponents(NULL);
}
// Username & Passwort setzten
SQLComponents->SQLConnection->Params->Values["User_Name"] = UserName.c_str();
SQLComponents->SQLConnection->Params->Values["Password"] = Password.c_str();
// Query setzten
SQLComponents->SQLClientDataSet->CommandText = Query1.c_str();
// connecten
SQLComponents->SQLConnection->Connected = true;
SQLComponents->SQLClientDataSet->Active = true;
// Datensatzt wird ausgewählt
Opts.Clear();
Opts << loCaseInsensitive;
SQLComponents->SQLClientDataSet->Locate("BLOBX", SearchKey, Opts);
// Edit Modus
SQLComponents->SQLClientDataSet->Edit();
// Blob wird in den selektierten Datensatzt copiert.
TBlobField* blobField = dynamic_cast <TBlobField*> (SQLComponents->SQLClientDataSet->FieldByName("BLOB"));
if (blobField == NULL) return;
blobField->LoadFromFile(BrowserFile);
// Änderungen werden an die DB übertragen
SQLComponents->SQLClientDataSet->ApplyUpdates(-1);
// disonnect
SQLComponents->SQLConnection->Connected = false;
SQLComponents->SQLClientDataSet->Active = false;
delete SQLComponents;
|
the Locate("BLOBX", SearchKey, Opts); command is necessary. |
|
| Back to top |
|
 |
|