public bool Insert(ClassReminderBLL u) { //Create a boolean variable and set its default value to false bool isSuccess = false; //Create an Object of SqlConnection to connect Database SqlConnection conn = new SqlConnection(myconnstrng); try { //Create a String Variable to Store the INSERT Query String sql = "INSERT INTO ClassTbl(ClassName, MeetingLink, AttendanceLink, DriveLink, Day, Hour, Min) VALUES (@ClassName, @MeetingLink, @AttendanceLink, @DriveLink, @Day, @Hour, @Min)"; //Create a SQL Command to pass the value in our query SqlCommand cmd = new SqlCommand(sql, conn); //Create the Parameter to pass get the value from UI and pass it on SQL Query above cmd.Parameters.AddWithValue("@ClassName", u.ClassName); cmd.Parameters.AddWithValue("@MeetingLink", u.MeetingLink); cmd.Parameters.AddWithValue("@AttendanceLink", u.AttendanceLink); cmd.Parameters.AddWithValue("@DriveLink", u.DriveLink); cmd.Parameters.AddWithValue("@Day", u.Day); cmd.Parameters.AddWithValue("@Hour", u.Hour); cmd.Parameters.AddWithValue("@Min", u.Min); //Open Database Connection conn.Open(); //Create an Integer VAriable to hold the value after the query is executed int rows = cmd.ExecuteNonQuery(); //The value of rows will be greater than 0 if the query is executed successfully //Else it'll be 0 if (rows > 0) { //Query Executed Successfully isSuccess = true; } else { //FAiled to Execute Query isSuccess = false; } } catch (Exception ex) { //DIsplay Error Message if there's any exceptional errors MessageBox.Show(ex.Message); } finally { //Close Database Connection conn.Close(); } return(isSuccess); }
public bool Update(ClassReminderBLL u) { //Create a Boolean variable and set its default value to false bool isSuccess = false; //Create an Object for Database Connection SqlConnection conn = new SqlConnection(myconnstrng); try { //Create a string variable to hold the sql query string sql = "UPDATE ClassTbl SET ClassName=@ClassName, MeetingLink=@MeetingLink, AttendanceLink=@AttendanceLink, DriveLink=@DriveLink, Day=@Day, Hour=@Hour, Min=@Min"; //Create Sql Command to execute query and also pass the values to sql query SqlCommand cmd = new SqlCommand(sql, conn); //Now Pass the values to SQL Query cmd.Parameters.AddWithValue("@ClassName", u.ClassName); cmd.Parameters.AddWithValue("@MeetingLink", u.MeetingLink); cmd.Parameters.AddWithValue("@AttendanceLink", u.AttendanceLink); cmd.Parameters.AddWithValue("@DriveLink", u.DriveLink); cmd.Parameters.AddWithValue("@Day", u.Day); cmd.Parameters.AddWithValue("@Hour", u.Hour); cmd.Parameters.AddWithValue("@Min", u.Min); //open Database Connection conn.Open(); //Create an integer variable to hold the value after the query is executed int rows = cmd.ExecuteNonQuery(); //If the query is executed successfully then the value of rows will be greater than 0 //else it'll be 0 if (rows > 0) { //Query Executed Successfully isSuccess = true; } else { //Failed to Execute Query isSuccess = false; } } catch (Exception ex) { //Display error message if there's any exceptional error MessageBox.Show(ex.Message); } finally { //Close Database Connection conn.Close(); } return(isSuccess); }
public bool Delete(ClassReminderBLL u) { //Create a boolean variable and set its default value to false bool isSuccess = false; //Create an object for SqlConnection SqlConnection conn = new SqlConnection(myconnstrng); try { //Create a string variable to hold the sql query to delete data String sql = "DELETE FROM ClassTbl WHERE ClassName=@ClassName"; //Create Sql Command to Execute the Query SqlCommand cmd = new SqlCommand(sql, conn); //Pass the value thorugh parameters cmd.Parameters.AddWithValue("@ClassName", u.ClassName); //Open the DAtabase Connection conn.Open(); //Create an integer variable to hold the value after query is executed int rows = cmd.ExecuteNonQuery(); //If the query is executed Successfully then the value of rows will be greater than zero(0) //Else it'll be zero(0) if (rows > 0) { //Query executed Successfully isSuccess = true; } else { //Failed to Execute Query isSuccess = false; } } catch (Exception ex) { //Display Error Message if there's any Excetionl errors MessageBox.Show(ex.Message); } finally { //CLose Database Connection conn.Close(); } return(isSuccess); }