Click here to Skip to main content
15,886,032 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
How to get data from database use object. Without dataset and datatable. just use object.
Posted
Comments
Aarti Meswania 7-Jan-13 8:15am    
please elobrate
do you mean by read data using datareader?

1 solution

Try:
using (SqlConnection con = new SqlConnection(strConnect))
    {
    con.Open();
    using (SqlCommand com = new SqlCommand("SELECT iD, description FROM myTable", con))
        {
        using (SqlDataReader reader = com.ExecuteReader())
            {
            while (reader.Read())
                {
                int id = (int) reader["iD"];
                string desc = (string) reader["description"];
                Console.WriteLine("ID: {0}\n    {1}", iD, desc);
                }
            }
        }
    }
 
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