Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Change Column Name In DataReader In C#?

I have SqlDataReader that gets returned from a ExecuteDataReader statement.

All I want is: change some column name in the data reader, just before binding to grid.

Here's the situation:

  1. First I build the structure Of grid (structure is in the table in database that was filled based on the output of a stored procedure in the system in the past)
  2. I execute data reader to execute stored procedure
  3. Binding the data reader to the grid

Here is the problem: if one column in the stored procedure is in upper case and related column in the grid is in lower case, the grid does not fill.

And I have a lot of stored procedures based on this architecture. Some of them have many rows to display. And because of that I use data reader for performance.

  1. I don't want to change the column name in the stored procedure (too much work)
  2. I don't want to copy the result of data reader to another data holder (because of overhead, and low performance)
  3. I just one way to change the column name of the data reader

    sqlDataReader reader; reader.executedatareadet();

For example after data reader is returned I have two columns (A,B).

I want to change column 'A' to 'a' (convert to lower case) before binding it to the grid like reader.GetName(i)

I want to be able to do something like

reader.SetName(i)

but it seams that we cant change the data reader column name

like image 694
abianari Avatar asked Dec 19 '12 06:12

abianari


1 Answers

  1. You can change the column names in GridView
  2. If possible alter the Stored Procedure with new column names
like image 200
andy Avatar answered Oct 18 '22 09:10

andy