 |
Club Builder Foro de C++Builder en español
|
| Ver tema anterior :: Ver tema siguiente |
| Autor |
Mensaje |
Max Invitado
|
Publicado: Mar 22 Jul, 2003 7:55 am Asunto: imagen en bd |
|
|
Hola Foro
Como hago para guardar una imagen en la base de datos (en un campo de tipo graphic) que no sea mediante un DBImage, sino mediante codigo.
Espero haberme hecho entender
Gracias |
|
| Volver arriba |
|
 |
_Viktor Master


Registrado: 20 Jul 2003Mensajes: 463Ubicación: Santiago, Los Angeles - Chile
|
Publicado: Mie 23 Jul, 2003 12:38 am Asunto: |
|
|
Mira, hace un tiempo use este codigo, espero q sirva:
| Código: |
//-------------------------------------------------------------
// Example 1: Inserting a bitmap using a BDE query component
void __fastcall TForm1::Button2Click(TObject *Sender)
{
// load a bitmap into a memory stream object
std::auto_ptr<TMemoryStream> stream (new TMemoryStream);
stream->LoadFromFile("androm.bmp");
stream->Position = 0;
// Assign the parameters of the query. The SQL property of the query
// is set to:
//
// insert image_test
// (
// string_field,
// image_field
// )
// values
// (
// :string_field,
// :image_field
// )
//
// Note that the image_field param should have its DataType set to ftBlob
//
Query1->Params->ParamByName("string_field")->AsString = "androm.bmp";
Query1->Params->ParamByName("image_field") ->SetBlobData(stream->Memory,
stream->Size);
// execute the query to perform the insert
Query1->ExecSQL();
}
//-------------------------------------------------------------
// Example 2: Inserting a bitmap using a ADO query component
void __fastcall TForm1::Button2Click(TObject *Sender)
{
// load a bitmap into a memory stream object
std::auto_ptr<TMemoryStream> stream (new TMemoryStream);
stream->LoadFromFile("androm.bmp");
stream->Position = 0;
// Assign the parameters of the query. The SQL property of the query
// is the same SQL from the BDE example. The image_field param should
// have its DataType set to ftVarBytes, ftBlob or ftGraphic
ADOQuery->Parameters->ParamByName("string_field")->Value= "androm.bmp";
ADOQuery->Parameters->ParamByName("image_field")->LoadFromStream(stream.get(),
ftGraphic);
// execute the query to perform the insert
ADOQuery->ExecSQL();
}
//-------------------------------------------------------------
// Example 3: Inserting a bitmap using a table component (BDE or ADO)
void __fastcall TForm1::Button2Click(TObject *Sender)
{
// load a bitmap into a memory stream object
std::auto_ptr<TMemoryStream> stream (new TMemoryStream);
stream->LoadFromFile("androm.bmp");
stream->Position = 0;
// Add a record to the table, fill in the fields, and then post the record.
// Note that Table1string_field and Table1image_field are persistent TField
// objects. The image field must be a TBlobField, or a TBlobField
// descendent or this code won't compile. TBlobField is the only field type
// that provides a LoadFromStream method. Also note that if you use
// FieldByName to reference the field, you will need to cast the result to
// TBlobField before you call LoadFromStream because FieldByName returns a
// TField pointer, not a TBlobField pointer.
//
the image_field property should a TBlobField.
Table1->Append();
Table1string_field->AsString = "androm.bmp";
Table1image_field ->LoadFromStream(stream.get(),
ftGraphic);
Table1->Post();
}
|
Disculpa que no te tradusca los comentarios, pero en fin, creo q es lo de menos, verdad?
Suerte!! _________________ "Ser inteligente no es ser mas, solo equivocarse menos y no usar Visual Basic"
Atte.
Victor Yañez
Apoyen el Proyecto OpenSource del Club Builder. Ya tenemos componentes Listos!!! |
|
| Volver arriba |
|
 |
Touchsoftwares Master


Registrado: 16 Dic 2002Mensajes: 869Ubicación: MEXICO Playa del Carmen
|
Publicado: Dom 27 Jul, 2003 2:00 am Asunto: |
|
|
dmDefiniciones->qryProduccionimagen->LoadFromFile("foto.jpg");
don qryProduccionimagen es un campo de una tabla o query que ya esta definido como objeto en tiempo de diseño _________________ Ing. Gabriel Góngora Navarrete
TouchSoftwares Inc
http://www.touchsoftwares.com |
|
| Volver arriba |
|
 |
|
|
No puedes publicar temas nuevos en este foro No puedes responder a temas en este foro No puedes editar tus mensajes en este foro No puedes borrar tus mensajes en este foro No puedes votar en las encuestas de este foro
|
© 2002–2026 Club Builder · Funciona con phpBB.
|