studentsystemdb.cs

来自「电子选课系统 电子选课系统电子选课系统电子选课系统」· CS 代码 · 共 84 行

CS
84
字号
using System;
using System.Data;
using System.Data.SqlClient;

namespace Park.Common
{
	/// <summary>
	/// StudentSystemDB 的摘要说明。
	/// </summary>
	public class StudentSystemDB
	{
		public static int AddClass(string studentid,string classid)
		{
			SqlConnection myConnection=Utils.GetConnection();

			SqlCommand myCommand = new SqlCommand("StudentSystem_Add_Class", myConnection);

			// Mark the Command as a SPROC
			myCommand.CommandType = CommandType.StoredProcedure;

			// Add Parameters to SPROC
			SqlParameter StudentID = new SqlParameter("@studentid", SqlDbType.NVarChar, 20);
			StudentID.Value = studentid;
			myCommand.Parameters.Add(StudentID);

			// Add Parameters to SPROC
			SqlParameter ClassID = new SqlParameter("@classid", SqlDbType.Int);
			ClassID.Value = classid;
			myCommand.Parameters.Add(ClassID);

			// Add Parameters to SPROC
			SqlParameter retval = new SqlParameter("@retval", SqlDbType.Int);
			retval.Direction = ParameterDirection.Output;
			myCommand.Parameters.Add(retval);

			// Execute the command
			myConnection.Open();

			myCommand.ExecuteNonQuery();		

			myCommand.Dispose();
			myConnection.Dispose();

			return  (int)retval.Value;
		}

		public static int DeleteClass(string studentid, string classid)
		{
			SqlConnection myConnection=Utils.GetConnection();

			SqlCommand myCommand = new SqlCommand("StudentSystem_Delete_Class", myConnection);

			// Mark the Command as a SPROC
			myCommand.CommandType = CommandType.StoredProcedure;

			// Add Parameters to SPROC
			SqlParameter StudentID = new SqlParameter("@studentid", SqlDbType.NVarChar, 20);
			StudentID.Value = studentid;
			myCommand.Parameters.Add(StudentID);

			// Add Parameters to SPROC
			SqlParameter ClassID = new SqlParameter("@classid", SqlDbType.Int);
			ClassID.Value = classid;
			myCommand.Parameters.Add(ClassID);

			// Add Parameters to SPROC
			SqlParameter retval = new SqlParameter("@retval", SqlDbType.Int);
			retval.Direction = ParameterDirection.Output;
			myCommand.Parameters.Add(retval);

			// Execute the command
			myConnection.Open();

			myCommand.ExecuteNonQuery();
			myCommand.Dispose();
			myConnection.Dispose();

			return (int)retval.Value;
		}

	}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?