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 static DataSet PatientInfoSearch(string id, string lname, string fname) { try { // open connection myConn.Open(); //clear any parameters cmdString.Parameters.Clear(); // command cmdString.Connection = myConn; cmdString.CommandType = CommandType.StoredProcedure; cmdString.CommandTimeout = 1500; cmdString.CommandText = "PatientInfoSearch"; // Define input parameter cmdString.Parameters.Add("@patientID", SqlDbType.VarChar, 6).Value = id; cmdString.Parameters.Add("@lname", SqlDbType.VarChar, 30).Value = lname; cmdString.Parameters.Add("@fname", SqlDbType.VarChar, 30).Value = fname; // 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(); } } } }