title: How to insert image into database using TADOQuery Component Only
body: <p>I have one simple fundamental issue, I am trying to insert image into the database using <code>Insert</code> statement with other column values also using <code>TADOQuery</code> component.</p>
  
  <p>Since the code is already written by somebody, some dummy sample code I would like to put here for your clarification with the respective steps.</p>
  
  <p>Please note that this was working fine with <code>TQuery</code> component, since I am replacing <code>TQuery</code> with <code>TADOQuery</code> component, I must do the same using <code>TADOQuery</code> component only. </p>
  
  <p>The same code should work for SQL Server as well as Oracle databases. </p>
  
  <p>The datatype of the column in which I am trying to insert the image is of type <code>VarBinary</code> in SQL Server database.</p>
  
  <p>Inserting an image into table using TQuery </p>
  
  <ol>
  <li><p>Creating an image using <code>TImage</code>. </p>
  
  <pre><code>msBinImgStream := TMemoryStream.Create; 
  imgCustom := TImage.Create(self); 
  imgJpg := TJPEGImage.Create; 
  </code></pre></li>
  <li><p>Converting the image to <code>TJpegImage</code> and saving to <code>TMemoryStream</code>. </p>
  
  <pre><code>imgJpg.Assign(imgCustom.Picture.Bitmap); 
  imgJpg.SaveToStream(msBinImgStream);
  </code></pre></li>
  <li><p>Inserting into the database by using <code>SetBlobdata</code> property of <code>TQuery</code> component. </p>
  
  <pre><code>sSql := 'INSERT INTO Table_Name(Column1, Column2, Column_Image) VALUES ( ''' + Value1 + ''', ''' + Value2 + ''', :pBlob)'; 
  qryTQuery.SQL.Add(sSQL); 
  qryTQuery.ParamByName('pBlob').SetBlobData(msBinImgStream.Memory, msBinImgStream.Size); 
  qryTQuery.ExecSQL; 
  </code></pre></li>
  </ol>
  
  <p>Now doing the same thing using <code>TADOQuery</code>:</p>
  
  <ol>
  <li>Able to create the image. </li>
  <li>Converting it to TJpeg and saving to <code>TMemoryStream</code>. </li>
  <li><p>Trying to insert the image into database using <code>LoadFromStream(stream, ftBlob)</code> but getting an error <em>"String or binary value may be truncated"</em>. </p>
  
  <pre><code>sSql := 'INSERT INTO Table_Name(Column1, Column2, Column_Image) VALUES ( ''' + Value1 + ''', ''' + Value2 + ''', :pBlob)'; 
  qryADOQuery.SQL.Add(sSQL); 
  qryADOQuery.Parameters.ParamByName('pBlob').LoadFromStream(msBinImgStream, ftBlob); 
  qryADOQuery.ExecSQL; 
  </code></pre></li>
  </ol>
  
  <p>Kindly let me know, with this approach how should I overcome this issue.</p>