Skip to Content
0
Former Member
May 26, 2010 at 01:47 PM

Blob object help

202 Views

Hi

I want to ad a blob object into master data line table.

My table is @CT_PF_CMG1.

this is my code

CompanyService ocomp = connection.GetCompany().GetCompanyService();
            BlobParams param = ocomp.GetDataInterface(CompanyServiceDataInterfaces.csdiBlobParams) as BlobParams;
            param.Table = "@CT_PF_CMG1";
            param.Field = "U_Description"; //This fild is used to store base64 string ? if so what type has it be ?
            BlobTableKeySegment seg = param.BlobTableKeySegments.Add();
            seg.Name = "Code"; //is this correct this is document lines table 
            seg.Value = "qwe";
            BlobTableKeySegment seg2 = param.BlobTableKeySegments.Add();
            seg2.Name = "LineId";//is this correct this is document lines table 
            seg2.Value = "1";
            Blob oblob = ocomp.GetDataInterface(CompanyServiceDataInterfaces.csdiBlob) as Blob;
            string base64;
            using (System.IO.FileStream fs=new System.IO.FileStream(filename,System.IO.FileMode.Open               ))
            {
                long fsize = fs.Length;
                 byte[] buf = new byte[fsize];
                fs.Read(buf, 0, (int)fsize);
                fs.Close();
                base64 = Convert.ToBase64String(buf);
            }
            oblob.Content = base64;
            try
            {
                ocomp.SetBlob(param,oblob);
            }catch(Exception ex)
            {
            }

it throws an error

 "CCompanyServices::SetBlob Cannot update database; no records found."

Thanks for an advice .