ReaderTest.cs
Dosyayı İndir
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
namespace DatabaseProject
{
public class ReaderTest
{
public void TestUnconditional() {
string connectionString = "server=localhost;DataBase=CourseDatabase;uid=sa;pwd=godoro";
SqlConnection connection = new SqlConnection(connectionString);
connection.Open();
String sql = "select * from Student";
SqlCommand command = new SqlCommand(sql, connection);
SqlDataReader reader = command.ExecuteReader();
while (reader.Read()) {
int studentId = (int)reader["StudentId"];
string firstName = (string)reader["FirstName"];
string lastName = (string)reader["LastName"];
DateTime birthDate = (DateTime)reader["BirthDate"];
bool isGraduated = (bool)reader["IsGraduated"];
double bodyWeight = (double)reader["BodyWeight"];
int gradeNumber = (int)reader["GradeNumber"];
Console.WriteLine(studentId + " , " + firstName + "," + lastName + " ,"
+birthDate + " , " + isGraduated + "," + bodyWeight, gradeNumber);
}
reader.Close();
connection.Close();
}
public void TestConditional()
{
string connectionString = "server=localhost;DataBase=CourseDatabase;uid=sa;pwd=godoro";
SqlConnection connection = new SqlConnection(connectionString);
connection.Open();
String sql = "select * from Student where IsGraduated=1";
SqlCommand command = new SqlCommand(sql, connection);
SqlDataReader reader = command.ExecuteReader();
while (reader.Read()) {
int studentId = (int)reader["StudentId"];
string firstName = (string)reader["FirstName"];
string lastName = (string)reader["LastName"];
DateTime birthDate = (DateTime)reader["BirthDate"];
bool isGraduated = (bool)reader["IsGraduated"];
double bodyWeight = (double)reader["BodyWeight"];
int gradeNumber = (int)reader["GradeNumber"];
Console.WriteLine(studentId + " , " + firstName + "," + lastName + " ,"
+ birthDate + " , " + isGraduated + "," + bodyWeight, gradeNumber);
}
reader.Close();
connection.Close();
}
}
}
Dosyayı İndir