studentclassdb.cs

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

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

namespace Park.Common
{
	/// <summary>
	/// StudentClassDB 的摘要说明。
	/// </summary>
	public class StudentClassDB
	{
		public static bool AddClass(string classname,out string id)
		{
			id = "";

			SqlConnection myConnection=Utils.GetConnection();

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

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

			// Add Parameters to SPROC
			SqlParameter ClassName = new SqlParameter("@classname", SqlDbType.VarChar, 30);
			ClassName.Value = classname;
			myCommand.Parameters.Add(ClassName);

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

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

			// Execute the command
			myConnection.Open();

			try
			{
				myCommand.ExecuteNonQuery();
			}
			catch(Exception )
			{
				myCommand.Dispose();
				myConnection.Dispose();
				return false;
			}	

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

			id=ID.Value.ToString();
			return  retval.Value.Equals(1);
		}	

		public static void DeleteClass(string classid)
		{
			SqlConnection myConnection=Utils.GetConnection();

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

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

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

			// Execute the command
			myConnection.Open();

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

			return ;
		}

	}
}

⌨️ 快捷键说明

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