Hi all!
I hope someone can help me out with this annoying problem. Please see this image for reference: http://www.flickr.com/photos/mattsmith321/2689459346/sizes/o/
I have a functioning application that is responsible for creating PDF Letters by combining data with a template (think mail merge). The PDF image/blob is stored in the database in a varbinary(max) field (called LetterPDF). On the DataTable that field maps to a byte[] (also called LetterPDF). The data access is built via DataTables on top of stored procedures. Everything (all CRUD functions) have worked great for about a year now.
Unfortunately, one of our list methods (GetLettersByStatus) is starting to blow up now because there are certain statuses that return several thousand records/letters. Given that each PDF image/blob is ~100K, returning that many records with that much data causes memory issues (understatement).
What I would like to do is modify the GetLettersByStatus sproc to dummy out the value for the PDF image/blob and continue using the existing DataTable structure. However, no matter how I try to return an empty/null value for that field, I keep running into errors with the DataTable mapping (not surprised really). Unfortunately, I can't passed it no matter how hard I try.
The error I am getting is this:
System.InvalidOperationException: Inconvertible type mismatch between SourceColumn 'LetterPDF' of Int32 and the DataColumn 'LetterPDF' of Byte[]..
Here is the select statement from the sproc:
SELECT [LetterID],
[LetterStatus],
[LetterTemplate],
[LetterDate],
[EntityID],
[EntityDate],
[ClientID],
[ClientFirstName],
[ClientLastName],
[ProviderID],
[ProviderName],
[LetterData],
[LetterPDF], -- <<<< HERE IS WHAT I WANT TO CHANGE
[PrintToPrintCenter],
[CustomPrinterName],
[NumPrintAttempts],
[LastStatusMessage],
[LastModifiedDate]
FROM [Letters] WITH ( NOLOCK )
WHERE [LetterStatus] = @LetterStatus
I have tried modifying the noted line above with the following with no success:
NULL AS [LetterPDF],
'' AS [LetterPDF],
0 AS [LetterPDF],
It chokes on the this.Adapter.Fill(dataTable) in the following generated code:
[global::System.ComponentModel.Design.HelpKeywordAttribute("vs.data.TableAdapter")]
[global::System.ComponentModel.DataObjectMethodAttribute(global::System.ComponentModel.DataObjectMethodType.Select, false)]
public virtual LetterDS.LetterDataTable GetLettersByStatus(global::System.Nullable<byte> LetterStatus) {
this.Adapter.SelectCommand = this.CommandCollection[4];
if ((LetterStatus.HasValue == true)) {
this.Adapter.SelectCommand.Parameters[1].Value = ((byte)(LetterStatus.Value));
}
else {
this.Adapter.SelectCommand.Parameters[1].Value = global::System.DBNull.Value;
}
LetterDS.LetterDataTable dataTable = new LetterDS.LetterDataTable();
this.Adapter.Fill(dataTable);
return dataTable;
}
I know the easy way around this is to just create a new DataTable that doesn't have the LetterPDF field, put my one method on it and call it a day. However, that seems like a cop-out. Given that everything works and is in production, I only want to affect this one method/sproc (GetLettersByStatus) and can't go mucking around to much.
Any help is appreciated!
Thanks,
Matt