473,322 Members | 1,431 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

Make a DataReader internally preformat every record

Pittaman
Hello,

Sorry about the title, I had a hard time explaining this.

I've done a little trick to solve a problem I was having with this third party control, and was wondering if anyone here could come up with a better solution. Because it never felt like the best solution...

I'm using System.Data.OracleClient and some third party control to export the data retrieved with a SQL command to an Excel file.

I was having some problems with the third party control because it would truncate the content of a field when it encountered a newline in the data. A requirement was that my tool should export pretty much any data. But with Text (varchar or whatever) data, the \n (chr(10))and \r (chr(13)) characters gave problems.

I couldn't do anything to the source code of the third party control, but I needed a way to escape these characters, hand them over to the third party control and then after that control had read the data, convert the characters back to what they should be (regardless of the fact that newlines in an excel sheet are not really that cool). It also did it when using the CSV export option btw, so I knew it wasn't a problem of the Excel exporter.

So my first thought of a solution was to have the SQL query replace those characters, but that was a bit to complicated. Next I came up with was to create a new class which inherits from OracleCommand, then create my own DataReader which would internally convert the characters.

So I'd have two classes: MyOracleCommand and MyOracleDataReader, each inhereting everything from their big brothers, but with overridden methods which return Strings, in which I would then escape the characters before returning them to the class user.

However, OracleCommand and OracleDataReader were not inheritable. Next thing I came up with was to make a wrapper class for both these classes and make them implement IDbCommand and IDataReader. This worked fine.

So now my custom datareader formats each field with strings as I want it to. The third party contron now uses my datareader, it is unaware of any modifications to the data. And at a later stage I format the data back to the original format (in fact just before the record is written to the excel file, using an event from the third party control).

I have two questions:

1) Why is the OracleCommand and OracleDataReader class not inheritable?

2) Anyone here ever had to do something similar? Am I missing a more obvious solution?
Aug 28 '07 #1
2 1437
1. These are sealed classes meaning that they cannot be inherated from.

2. I really cant figure out a better way than what you did for the unique problem at the moment except replace that control. I would have probaly retrived the data as a dataset and looped though that to replace the characters and gave that to the control.

As long as the end result is what you want, move on to the next task.
Its really not worth spending any more time over.
Aug 29 '07 #2
Thanks for the reply.

I know they are sealed classes, I was just wondering if there was a good reason for it.

A DataSet was out of the question because of the size of the tables it'll be exporting... a DataReader is more efficient in such a case, but with some drawbacks obviously.

Don't worry, I'm doing this forum in my spare time ;) just out of interest.

1. These are sealed classes meaning that they cannot be inherated from.

2. I really cant figure out a better way than what you did for the unique problem at the moment except replace that control. I would have probaly retrived the data as a dataset and looped though that to replace the characters and gave that to the control.

As long as the end result is what you want, move on to the next task.
Its really not worth spending any more time over.
Aug 29 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Jason Huang | last post by:
Hi, Is it possible to bind DataReader to a DataGrid in C# windows form? And how? And can we update data in a DataSet by using the DataReader? Thanks for help. Jason
14
by: Jacko | last post by:
Hi guys, Say I made a SELECT statement to my sql DB that would return 50 rows that I will use a sqldatareader to access. Instead of iterating through each and every row of the datareader, I'd...
12
by: Thomas Scheiderich | last post by:
I have 2 dropdowns that are exactly the same and I don't want to re-read for each. Is there a way to do something like below where I read the data, bind to depCity1 and then bind to destCity2. ...
4
by: Shapper | last post by:
Hello, I have created a datareader function in a asp.net/vb web site. The datareader returns only one record with 2 fields: and In the same aspx.vb I want to use this values as follows:...
15
by: Rob Nicholson | last post by:
I'm starting to worry a bit now. We're getting the above error when two users hit the same database/page on an ASP.NET application using ADO.NET, talking to a SQL 7 server. The error is perfectly...
7
by: Varangian | last post by:
Hi all, the question I want to ask if the conversion of a DataReader to a Table looping through the DataReader is better than using the Fill Method of the DataAdapter... I'm asking because...
6
by: dejavue82 | last post by:
This is the result of a JOINed query: question answer 1 a1 1 a2 1 a3 1 a4 2 a1 2 a2
2
by: Chris | last post by:
>From just about everything I have read, a DataReader reads only one record at a time from a database and only caches that one record in the client's memmory. However, a colleague of mine noted...
7
by: =?Utf-8?B?UGV0ZXI=?= | last post by:
I have read some articles state that DataSet should NOT be used for large resultset. What does "large" mean? Is "large" based on # of rows/columns and/or memory required to hold the original and...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.