Click here to Skip to main content
15,907,281 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I just want to read value's of all rows in one column which is retrevied using datareader

like datareader show only one row value at one time and then second and so on.

i want to read all value's at once and assing these values to other varriable's that's it.
Posted
Updated 21-Apr-14 2:26am
v2
Comments
Bh@gyesh 21-Apr-14 3:27am    
Hi,
What does it mean - " 8 rows in one column"?
can you give some example?
OriginalGriff 21-Apr-14 3:34am    
This is not a good question - we cannot work out from that little what you are trying to do.
Remember that we can't see your screen, access your HDD, or read your mind.
Use the "Improve question" widget to edit your question and provide better information.
Telstra 21-Apr-14 4:31am    
What type of coloumn? From gridview coloumn or database table coloumn or anything else?? please elaborate your question more so that we can help you to achieve your task. We are happy to help you
RajeshwarReddy@.Net 21-Apr-14 4:57am    
what i understand form your statement is 'you want to save/show the information contained in 8 rows to 1 row with irrespective of column".

Is I'm right?
thatraja 21-Apr-14 6:08am    
Not clear. Update your question

Hello,

I am assuming that you want to retrieve the column value from multiple rows as a concatenated string. If this is the scenario then in SQL Server you can do so by using following Stored Proc.
SQL
CREATE FUNCTION getRows() AS
BEGIN
    DECLARE @Names VARCHAR(8000)

    SELECT @Names = '';
    SELECT @Names = @Names + ',' + ISNULL(UserName, 'N/A')
    FROM users

    RETURN @Names;
END;

Following code snippet shows how you can call this proc from your client.
C#
SqlConnection sqlCon = new SqlConnection("YOUR CON STR");
SqlCommand cmd = new SqlCommand();
SqlDataReader reader;

cmd.CommandText = "getRows";
cmd.CommandType = CommandType.StoredProcedure;
cmd.Connection = sqlCon;

sqlCon.Open();

reader = cmd.ExecuteReader();
// Code to Access the data


sqlConnection1.Close();

Regards,
 
Share this answer
 
You can use data table or dataset to read collection of values at once.

Ref Example:

sqlConnection = new SqlConnection(ConnString);
string sql = "Your Query";
SqlCommand command = new SqlCommand(sql, sqlConnection);
SqlDataAdapter da = new SqlDataAdapter(command);
da.Fill(dt);
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900