Click here to Skip to main content
15,891,033 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
hi,

Anyone know C# code for this..

How to retrieve data from database using datareader?
Posted

Dear Friend,

Please follow this link:-

http://www.akadia.com/services/dotnet_data_reader.html[^]

Hope it will help you out.

Thanks
 
Share this answer
 
Comments
CRDave1988 13-Feb-12 4:34am    
5 very good examples
Varun Sareen 13-Feb-12 5:06am    
thanks
Check this link

http://www.akadia.com/services/dotnet_data_reader.html[^]

It will help You
 
Share this answer
 
Comments
CRDave1988 13-Feb-12 4:34am    
5 very good examples
Aniket Yadav 13-Feb-12 4:36am    
Thanks CRDave1988 ;-)
see this

C#
private static void ReadOrderData(string connectionString)
{
    string queryString =
        "SELECT OrderID, CustomerID FROM dbo.Orders;";

    using (SqlConnection connection =
               new SqlConnection(connectionString))
    {
        SqlCommand command =
            new SqlCommand(queryString, connection);
        connection.Open();

        SqlDataReader reader = command.ExecuteReader();

        // Call Read before accessing data.
        while (reader.Read())
        {
            Console.WriteLine(String.Format("{0}, {1}",
                reader[0], reader[1]));
        }

        // Call Close when done reading.
        reader.Close();
    }
}

From : http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqldatareader.aspx[^]
 
Share this answer
 
Try
this [^]
and this[^]
 
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