magritton
5/1/2014 - 2:43 PM

Queries the SQL server and returns a binary object for further processing

Queries the SQL server and returns a binary object for further processing

public byte[] getAttachment(FileAttachment fa)
        {
            byte[] bytes;

            string strConnectionString = @"Password=FaY5FEC5;Persist Security Info=True;User ID=OPWDataWriter;Initial Catalog=OPWBI;Data Source=opwsql03\sp2013tabular";
            string strQuery = string.Format(@"SELECT FileData FROM ar_Invoice_Attachments WHERE InvoiceNumber = '{0}'
                and CustomerNumber = '{1}' and CompanyName = '{2}'  and FileName = '{3}'", fa.invoiceNumber, fa.customerNumber, fa.companyName, fa.fileName);

            SqlConnection sc = new SqlConnection(strConnectionString);
            sc.Open();

            SqlCommand queryCommand = new SqlCommand(strQuery, sc);
            SqlDataReader dr = queryCommand.ExecuteReader();
            dr.Read();
            bytes = (byte[])dr["FileData"];
            return bytes;
        }