ProcedureTest.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 ProcedureTest
{
public void TestUpdate() {
string connectionString = "server=localhost;DataBase=CourseDatabase;uid=sa;pwd=godoro";
SqlConnection connection = new SqlConnection(connectionString);
connection.Open();
SqlCommand command = new SqlCommand("MoveStudent", connection);
command.CommandType = CommandType.StoredProcedure;
command.Parameters.AddWithValue("@StudentId", 2);
command.Parameters.AddWithValue("@SchoolId", 1);
command.ExecuteNonQuery();
connection.Close();
}
public void TestQuery()
{
string connectionString = "server=localhost;DataBase=CourseDatabase;uid=sa;pwd=godoro";
SqlConnection connection = new SqlConnection(connectionString);
connection.Open();
SqlCommand command = new SqlCommand("GetStudentNamesBySchoolId", connection);
command.CommandType = CommandType.StoredProcedure;
command.Parameters.AddWithValue("@SchoolId", 2);
SqlDataReader reader = command.ExecuteReader();
while (reader.Read()) {
string firstName = (string)reader["FirstName"];
string lastName = (string)reader["LastName"];
Console.WriteLine(firstName + " " + lastName);
}
connection.Close();
}
}
}
Dosyayı İndir