From d257715541d962d182aeeeb1c0dbbec631570a36 Mon Sep 17 00:00:00 2001 From: EggMan20339 <99349302+EggMan20339@users.noreply.github.com> Date: Wed, 14 Feb 2024 17:40:16 -0500 Subject: [PATCH] updated datatier --- .../Louis'-Pharmacy_CNSA212-FP.csproj | 1 + .../PharmacyDataTier.cs | 89 ++++++++++++++++++- 2 files changed, 89 insertions(+), 1 deletion(-) diff --git a/Louis'-Pharmacy_CNSA212-FP/Louis'-Pharmacy_CNSA212-FP.csproj b/Louis'-Pharmacy_CNSA212-FP/Louis'-Pharmacy_CNSA212-FP.csproj index a30432b..914ecde 100644 --- a/Louis'-Pharmacy_CNSA212-FP/Louis'-Pharmacy_CNSA212-FP.csproj +++ b/Louis'-Pharmacy_CNSA212-FP/Louis'-Pharmacy_CNSA212-FP.csproj @@ -34,6 +34,7 @@ + diff --git a/Louis'-Pharmacy_CNSA212-FP/PharmacyDataTier.cs b/Louis'-Pharmacy_CNSA212-FP/PharmacyDataTier.cs index a4d9796..0d91156 100644 --- a/Louis'-Pharmacy_CNSA212-FP/PharmacyDataTier.cs +++ b/Louis'-Pharmacy_CNSA212-FP/PharmacyDataTier.cs @@ -1,7 +1,94 @@ -namespace Louis__Pharmacy_CNSA212_FP +using System; +using System.Configuration; +using System.Data; +using System.Windows.Forms; +using System.Data.SqlClient; + +namespace Louis__Pharmacy_CNSA212_FP { public class PharmacyDataTier { + + static String connString = ConfigurationManager.ConnectionStrings["ConnString"].ConnectionString; + static SqlConnection myConn = new SqlConnection(connString); + static System.Data.SqlClient.SqlCommand cmdString = new System.Data.SqlClient.SqlCommand(); + public DataSet GetStudents(string studid, string lname, DateTime dob) + { + try + { + // open connection + myConn.Open(); + //clear any parameters + cmdString.Parameters.Clear(); + // command + cmdString.Connection = myConn; + cmdString.CommandType = CommandType.StoredProcedure; + cmdString.CommandTimeout = 1500; + cmdString.CommandText = "SearchStudent"; + // Define input parameter + cmdString.Parameters.Add("@studentid", SqlDbType.VarChar, 6).Value = studid; + cmdString.Parameters.Add("@lname", SqlDbType.VarChar, 25).Value = lname; + cmdString.Parameters.Add("@dob", SqlDbType.Date).Value = dob; + // adapter and dataset + SqlDataAdapter aAdapter = new SqlDataAdapter(); + aAdapter.SelectCommand = cmdString; + DataSet aDataSet = new DataSet(); + + // fill adapter + aAdapter.Fill(aDataSet); + + // return dataSet + return aDataSet; + } + catch (Exception ex) + { + throw new ArgumentException(ex.Message); + } + finally + { + myConn.Close(); + } + } + + + public DataSet GetStudents(string StuID) + { + + + try + { + // open connection + myConn.Open(); + //clear any parameters + cmdString.Parameters.Clear(); + // command + cmdString.Connection = myConn; + cmdString.CommandType = CommandType.StoredProcedure; + cmdString.CommandTimeout = 1500; + cmdString.CommandText = "GetByStudentIDS"; + // Define input parameter + cmdString.Parameters.Add("@studentid", SqlDbType.VarChar, 6).Value = StuID; + // adapter and dataset + SqlDataAdapter aAdapter = new SqlDataAdapter(); + aAdapter.SelectCommand = cmdString; + DataSet aDataSet = new DataSet(); + + // fill adapter + aAdapter.Fill(aDataSet); + + // return dataSet + return aDataSet; + } + catch (Exception ex) + { + throw new ArgumentException(ex.Message); + } + finally + { + myConn.Close(); + } + } + } } \ No newline at end of file