Click here to Skip to main content
15,886,652 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
how to retrive data row by row in C#.net....from SQL serever 2005
Posted
Comments
Not clear. Please explain again with some code.

1 solution

you can read data using sqldatareader
below is the sample code

using System;
using System.Data.SqlClient;

class Program
{
static void Main()
{
//
// You need to access the project's connection string here.
//
string connectionString = ConsoleApplication1.Properties.Settings.Default.ConnectionString;
//
// Create new SqlConnection object.
//
using (SqlConnection connection = new SqlConnection(connectionString))
{
connection.Open();
//
// Create new SqlCommand object.
//
using (SqlCommand command = new SqlCommand("SELECT * FROM Dogs1", connection))
{
//
// Invoke ExecuteReader method.
//
SqlDataReader reader = command.ExecuteReader();
while (reader.Read())
{
int weight = reader.GetInt32(0); // Weight int
string name = reader.GetString(1); // Name string
string breed = reader.GetString(2); // Breed string
//
// Write the values read from the database to the screen.
//
Console.WriteLine("Weight = {0}, Name = {1}, Breed = {2}", weight, name, breed);
}
}
}
}
}
 
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