Exemplo n.º 1
0
        public bool Insert(contactClass c)
        {
            bool          isSUCCESS = false;
            SqlConnection conn      = new SqlConnection(myconnstrng);

            try
            {
                string     sql = "INSERT INTO tbl_contact(FirstName,LastName,ContactNo,Address,Gender) VALUES (@FirstName,@LastName,@ContactNo,@Address,@Gender)";
                SqlCommand cmd = new SqlCommand(sql, conn);
                cmd.Parameters.AddWithValue("@FirstName", c.FirstName);
                cmd.Parameters.AddWithValue("@LastName", c.LastName);
                cmd.Parameters.AddWithValue("@ContactNo", c.ContactNo);
                cmd.Parameters.AddWithValue("@Address", c.Address);
                cmd.Parameters.AddWithValue("@Gender", c.Gender);
                conn.Open();
                int rows = cmd.ExecuteNonQuery();
                if (rows > 0)
                {
                    isSUCCESS = true;
                }
                else
                {
                    isSUCCESS = false;
                }
            }
            catch (Exception ex)
            {
            }
            finally
            {
                conn.Close();
            }
            return(isSUCCESS);
        }
Exemplo n.º 2
0
        public bool Delete(contactClass c)
        {
            //Create a default return value and set its calue to ofalse
            bool          isSuccess = false;
            SqlConnection conn      = new SqlConnection(myconnstrng);

            try
            {
                string sql = "DELETE FROM tbl_contact WHERE ContactID = @ContactID";

                SqlCommand cmd = new SqlCommand(sql, conn);
                cmd.Parameters.AddWithValue("@ContactID", c.ContactID);
                conn.Open();
                int rows = cmd.ExecuteNonQuery();
                //if query runs successfully then the calue of rows will be greather than 0 else less
                if (rows > 0)
                {
                    isSuccess = true;
                }
                else
                {
                    isSuccess = false;
                }
            }
            catch (Exception ex)
            {
            }
            finally
            {
                conn.Close();
            }
            return(isSuccess);
        }
Exemplo n.º 3
0
        public bool insert(contactClass c)
        {
            bool          isSuccess = false;
            SqlConnection conn      = new SqlConnection(myconnStrig);

            try
            {
                string     sql = "insert into contact(name,phone,email,gender,address) values (@name,@phone,@email,@gender,@address)";
                SqlCommand cmd = new SqlCommand(sql, conn);
                cmd.Parameters.AddWithValue("@name", c.name);
                cmd.Parameters.AddWithValue("@phone", c.phone);
                cmd.Parameters.AddWithValue("@email", c.email);
                cmd.Parameters.AddWithValue("@gender", c.gender);
                cmd.Parameters.AddWithValue("@address", c.address);

                conn.Open();
                int raws = cmd.ExecuteNonQuery();
                if (raws > 0)
                {
                    isSuccess = true;
                }
                else
                {
                    isSuccess = false;
                }
            }
            catch (Exception ex) {
            }
            finally {
                conn.Close();
            }
            return(isSuccess);
        }
Exemplo n.º 4
0
        //method to delete data from database

        public bool Delete(contactClass c)
        {
            //create a default return=false
            bool          isSuccess = false;
            SqlConnection conn      = new SqlConnection(myConnString);

            try
            {
                string     sql = "DELETE FROM tbl_contact WHERE ContactID=@ContactID";
                SqlCommand cmd = new SqlCommand(sql, conn);
                cmd.Parameters.AddWithValue("@ContactID", c.ContactID);
                conn.Open();
                int rows = cmd.ExecuteNonQuery();
                if (rows > 0)
                {
                    isSuccess = true;
                }
                else
                {
                    isSuccess = false;
                }
            }
            catch (Exception ex)
            {
            }
            finally
            {
                conn.Close();
            }


            return(isSuccess);
        }
Exemplo n.º 5
0
        public bool delete(contactClass c)
        {
            bool          isSucess = false;
            SqlConnection conn     = new SqlConnection(myconnStrig);

            try
            {
                string     sql = "delete from contact where id=@id;";
                SqlCommand cmd = new SqlCommand(sql, conn);
                cmd.Parameters.AddWithValue("@id", c.id);
                conn.Open();

                int raws = cmd.ExecuteNonQuery();
                if (raws > 0)
                {
                    isSucess = true;
                }
                else
                {
                    isSucess = false;
                }
            }
            catch (Exception ex)
            {
            }
            finally
            {
                conn.Close();
            }


            return(isSucess);
        }
Exemplo n.º 6
0
        // update database
        public bool Delete(contactClass c)
        {
            bool isSuccess = false;

            SqlConnection conn = new SqlConnection(myconnstrng);

            try
            {
                string     sql = "Delete FROM tbl_contact WHERE ContactID=@ContactID";
                SqlCommand cmd = new SqlCommand(sql, conn);
                cmd.Parameters.AddWithValue("@ContactID", c.ContactID);

                conn.Open();
                int rows = cmd.ExecuteNonQuery();

                if (rows > 0)
                {
                    isSuccess = true;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error: " + ex.Message);
            }
            finally
            {
                conn.Close();
            }

            return(isSuccess);
        }
Exemplo n.º 7
0
        //method to update data in database from our application
        public bool Update(contactClass c)
        {
            //create a default return type and set its default value to false
            bool isSuccess = false;

            SqlConnection conn = new SqlConnection(myconnstrng);

            try
            {
                //sql to update data in our data base
                string sql = "UPDATE tbl_contact SET FirstName=@FirstName , LastName=@LastName , ContactNo=@ContactNo , Address=@Address , Gender=@Gender WHERE ContactID=@ContactID";

                //creating sql command
                SqlCommand cmd = new SqlCommand(sql, conn);

                //create parameters to add value
                cmd.Parameters.AddWithValue("@FirstName", c.FirstName);
                cmd.Parameters.AddWithValue("@LastName", c.LastName);
                cmd.Parameters.AddWithValue("@ContactNo", c.ContactNo);
                cmd.Parameters.AddWithValue("@Address", c.Address);
                cmd.Parameters.AddWithValue("@Genders", c.Gender);
                cmd.Parameters.AddWithValue("ContactID", c.ContactID);

                //open Database connection
                conn.Open();

                int rows = cmd.ExecuteNonQuery();

                //if the querry runs successfully then the value of rows will be greater than zero else its value will be zero
                if (rows > 0)
                {
                    isSuccess = true;
                }

                else
                {
                    isSuccess = false;
                }
            }

            catch (Exception ex)
            {
            }

            finally
            {
                conn.Close();
            }

            return(isSuccess);
        }
Exemplo n.º 8
0
        //Inserting Data into Database
        public bool Insert(contactClass c)
        {
            //Creating Default return type  and setting its value to false
            bool isSuccess = false;

            //Step 1 :   connect Database
            SqlConnection conn = new SqlConnection(myconnstrng);

            try
            {
                //Step 2 : Create a SQL Querry to insert Data
                string sql = "INSERT INTO tbl_contact(FirstName ,  LastName , ContactNo , Address , Gender) VALUES (@FirstName ,  @LastName , @ContactNo , @Address , @Gender)";

                //Creating sql command using sql and conn
                SqlCommand cmd = new SqlCommand(sql, conn);

                //Create Parameter to add data
                cmd.Parameters.AddWithValue("@FirstName", c.FirstName);
                cmd.Parameters.AddWithValue("@LastName", c.LastName);
                cmd.Parameters.AddWithValue("@ContactNo", c.ContactNo);
                cmd.Parameters.AddWithValue("@Address", c.Address);
                cmd.Parameters.AddWithValue("@Gender", c.Gender);

                // connection open here
                conn.Open();
                int rows = cmd.ExecuteNonQuery();

                //if the querry runs successfully then the values of rows will be greater than zero else value will be 0
                if (rows > 0)
                {
                    isSuccess = true;
                }

                else
                {
                    isSuccess = false;
                }
            }

            catch (Exception ex)
            {
            }

            finally
            {
                conn.Close();
            }

            return(isSuccess);
        }
Exemplo n.º 9
0
        //method to delete data from database
        public bool Delete(contactClass c)
        {
            //create a default returnvalue and set its value to false
            bool isSuccess = false;

            // create sql connection
            SqlConnection conn = new SqlConnection(myconnstrng);

            try
            {
                //sql to delete data
                string sql = "DELETE FROM tbl_contact WHERE ContactID=@ContactID";

                //create sql command
                SqlCommand cmd = new SqlCommand(sql, conn);
                cmd.Parameters.AddWithValue("@ContactID", c.ContactID);

                //open connection
                conn.Open();

                int rows = cmd.ExecuteNonQuery();

                //if the querry runs successfully then the value of rows will be greater than zero else its value will be zero
                if (rows > 0)
                {
                    isSuccess = true;
                }

                else
                {
                    isSuccess = false;
                }
            }

            catch (Exception ex)
            {
            }

            finally
            {
                //close connnection
                conn.Close();
            }

            return(isSuccess);
        }
Exemplo n.º 10
0
        //Inserting data into data base
        public bool Insert(contactClass c)
        {
            //Create a default return type and set def value to false
            bool isSuccess = false;

            //step 1 connect db
            SqlConnection conn = new SqlConnection(myconnstrng);

            try
            {
                //step 2 create SQL Query to insert data

                string sql = "INSERT INTO tbl_contact (FirstName, LastName, ContactNo,Address,Gender) VALUES(@FirstName,@LastName,@ContactNo,@Address,@Gender)";

                //cREATE SQL COMMAND USING SQL AND CONN
                SqlCommand cmd = new SqlCommand(sql, conn);
                //Create parameters to add data
                cmd.Parameters.AddWithValue("@FirstName", c.FirstName);
                cmd.Parameters.AddWithValue("@LastName", c.LastName);
                cmd.Parameters.AddWithValue("@ContactNo", c.ContactNo);
                cmd.Parameters.AddWithValue("@Address", c.Address);
                cmd.Parameters.AddWithValue("@Gender", c.Gender);

                //connection
                conn.Open();
                int rows = cmd.ExecuteNonQuery();
                //if query runs successfully then the calue of rows will be greather than 0 else less
                if (rows > 0)
                {
                    isSuccess = true;
                }
                else
                {
                    isSuccess = false;
                }
            }
            catch (Exception ex)
            {
            }
            finally
            {
                conn.Close();
            }
            return(isSuccess);
        }
Exemplo n.º 11
0
        //method to update data in database from our application
        public bool Update(contactClass c)
        {
            //create a  return type and set its default value to false
            bool isSuccess = false;

            SqlConnection conn = new SqlConnection(myConnString);

            try
            {
                //sql to update
                string sql = "UPDATE tbl_contact SET FirstName=@FirstName , LastName=@LastName , ContactNo=@ContactNo , Address=@Address , Gender=@Gender WHERE ContactID=@ContactID ";
                //creating sql command
                SqlCommand cmd = new SqlCommand(sql, conn);

                // create paramters to add values
                cmd.Parameters.AddWithValue("@FirstName", c.FirstName);
                cmd.Parameters.AddWithValue("@LastName", c.LastName);
                cmd.Parameters.AddWithValue("@ContactNo", c.ContactNo);
                cmd.Parameters.AddWithValue("@Address", c.Address);
                cmd.Parameters.AddWithValue("@Gender", c.Gender);
                cmd.Parameters.AddWithValue("@ContactID", c.ContactID);
                //open database connection
                conn.Open();

                int rows = cmd.ExecuteNonQuery();
                if (rows > 0)
                {
                    isSuccess = true;
                }
                else
                {
                    isSuccess = false;
                }
            }
            catch (Exception ex)
            {
            }
            finally
            {
                conn.Close();
            }
            return(isSuccess);
        }
Exemplo n.º 12
0
        //Inserting DAta into Database
        public bool Insert(contactClass c)
        {
            //Creating a default return type and setting its value to false
            bool isSuccess = false;

            //STep 1: Connect DAtabase
            SqlConnection conn = new SqlConnection(myconnstrng);

            try
            {
                //STep 2: Create a SQL Query to insert DAta
                string sql = "INSERT INTO tbl_contact (Name, Number, Date, Computer) VALUES (@Name, @Number, @Date, @Computer)";
                //Creating SQL Command using sql and conn
                SqlCommand cmd = new SqlCommand(sql, conn);
                //Create Parameters to add data
                cmd.Parameters.AddWithValue("@Name", c.Name);
                cmd.Parameters.AddWithValue("@Number", c.Number);
                cmd.Parameters.AddWithValue("@Date", c.Date);
                cmd.Parameters.AddWithValue("@Computer", c.Computer);


                //Connection Open Here
                conn.Open();
                int rows = cmd.ExecuteNonQuery();
                //If the query runs successfully then the value of rows will be greater than zero else its value will be 0
                if (rows > 0)
                {
                    isSuccess = true;
                }
                else
                {
                    isSuccess = false;
                }
            }
            catch (Exception ex)
            {
            }
            finally
            {
                conn.Close();
            }
            return(isSuccess);
        }
Exemplo n.º 13
0
        //Method to update data in database from our application
        public bool Update(contactClass c)
        {
            //Create a default return type and set its default value to false
            bool          isSuccess = false;
            SqlConnection conn      = new SqlConnection(myconnstrng);

            try
            {
                //SQL to update data in our Database
                string sql = "UPDATE tbl_contact SET Name=@Name, Number=@Number, Date=@Date, Computer=@Computer WHERE ContactID=@ContactID";

                //Creating SQL Command
                SqlCommand cmd = new SqlCommand(sql, conn);
                //Create Parameters to add value
                cmd.Parameters.AddWithValue("@Name", c.Name);
                cmd.Parameters.AddWithValue("@Number", c.Number);
                cmd.Parameters.AddWithValue("@Date", c.Date);
                cmd.Parameters.AddWithValue("@Computer", c.Computer);

                cmd.Parameters.AddWithValue("ContactID", c.ContactID);
                //Open DAtabase Connection
                conn.Open();

                int rows = cmd.ExecuteNonQuery();
                //if the query runs sucessfully then the value of rows will be greater than zero else its value will be zero
                if (rows > 0)
                {
                    isSuccess = true;
                }
                else
                {
                    isSuccess = false;
                }
            }
            catch (Exception ex)
            {
            }
            finally
            {
                conn.Close();
            }
            return(isSuccess);
        }
Exemplo n.º 14
0
        //Method to Delete Data from DAtabase
        public bool Delete(contactClass c)
        {
            //Create a default return value and set its value to false
            bool isSuccess = false;
            //Create SQL Connection
            SqlConnection conn = new SqlConnection(myconnstrng);

            try
            {
                //SQL To Delte DAta
                string sql = "DELETE FROM tbl_contact WHERE ContactID=@ContactID";

                //Creating SQL Command
                SqlCommand cmd = new SqlCommand(sql, conn);
                cmd.Parameters.AddWithValue("@ContactID", c.ContactID);
                //Open Connection
                conn.Open();
                int rows = cmd.ExecuteNonQuery();
                //If the query run sucessfully then the value of rows is greater than zero else its value is 0
                if (rows > 0)
                {
                    isSuccess = true;
                }
                else
                {
                    isSuccess = false;
                }
            }
            catch (HoteliException ex)
            {
                MessageBox.Show(ex.Message.ToString());
            }
            finally
            {
                //Close Connection
                conn.Close();
            }
            return(isSuccess);
        }
        public bool Update(contactClass c)
        {
            bool          isSuccess = false;
            SqlConnection conn      = new SqlConnection(myconnString);

            try
            {
                string     sql = "UPDATE tblContact SET FirstName =@FirstName, LastName=@LastName, ContactNo = @ContactNo, Address=@address, Gender= @Gender WHER ContactId = @ContactId";
                SqlCommand cmd = new SqlCommand(sql, conn);

                cmd.Parameters.AddWithValue("@FirstName", c.FirstName);
                cmd.Parameters.AddWithValue("@LastName", c.LastName);
                cmd.Parameters.AddWithValue("@ContactNo", c.ContactNo);
                cmd.Parameters.AddWithValue("@Address", c.Address);
                cmd.Parameters.AddWithValue("@Gender", c.Gender);
                cmd.Parameters.AddWithValue("@ContactId", c.ContactId);

                conn.Open();
                int rows = cmd.ExecuteNonQuery();

                if (rows > 0)
                {
                    isSuccess = true;
                }
                else
                {
                    isSuccess = false;
                }
            }
            catch (Exception ex)
            {
            }
            finally
            {
                conn.Close();
            }
            return(isSuccess);
        }
Exemplo n.º 16
0
        //Method to delete data from database

        public bool Delete(contactClass c)
        {
            //Create a default return value and set value to false
            bool isSuccess = false;
            //Create SQL Connection
            SqlConnection conn = new SqlConnection(myconnstrng);

            try
            {
                //SQL to Delete Data
                string sql = "DELETE FROM tbl_contact WHERE ContactID=@ContactID";

                //Creating SQL Command
                SqlCommand cmd = new SqlCommand(sql, conn);
                cmd.Parameters.AddWithValue("@ContactID", c.ContactID);
                conn.Open();
                int rows = cmd.ExecuteNonQuery();
                //if rows is greater than zero it was successfull else it value will be zero
                if (rows > 0)
                {
                    isSuccess = true;
                }
                else
                {
                    isSuccess = false;
                }
            }
            catch (Exception ex)
            {
            }
            finally
            {
                conn.Close();
            }
            return(isSuccess);
        }
Exemplo n.º 17
0
        public bool Update(contactClass c)
        {
            bool          isSuccess = true;
            SqlConnection conn      = new SqlConnection(myconnStrig);

            try
            {
                string     sql = "update table contact set name=@name,phone=@pnone,email=@email,gender=@gender,address=@address where id=@id";
                SqlCommand cmd = new SqlCommand(sql, conn);
                cmd.Parameters.AddWithValue("@name", c.name);
                cmd.Parameters.AddWithValue("@phone", c.phone);
                cmd.Parameters.AddWithValue("@email", c.email);
                cmd.Parameters.AddWithValue("@gender", c.gender);
                cmd.Parameters.AddWithValue("@address", c.address);
                cmd.Parameters.AddWithValue("@id", c.id);

                conn.Open();
                int raws = cmd.ExecuteNonQuery();
                if (raws > 0)
                {
                    isSuccess = true;
                }
                else
                {
                    isSuccess = false;
                }
            }
            catch (Exception ex)
            {
            }
            finally {
                conn.Close();
            }

            return(isSuccess);
        }
Exemplo n.º 18
0
        // update database
        public bool Update(contactClass c)
        {
            bool isSuccess = false;

            SqlConnection conn = new SqlConnection(myconnstrng);

            try
            {
                string     sql = "UPDATE tbl_contact SET FirstName=@FirstName, LastName=@LastName, ContactNumber=@ContactNumber, Address=@Address, Gender=@Gender WHERE ContactID=@ContactID";
                SqlCommand cmd = new SqlCommand(sql, conn);
                cmd.Parameters.AddWithValue("@ContactID", c.ContactID);
                cmd.Parameters.AddWithValue("@FirstName", c.FirstName);
                cmd.Parameters.AddWithValue("@LastName", c.LastName);
                cmd.Parameters.AddWithValue("@ContactNumber", c.ContactNumber);
                cmd.Parameters.AddWithValue("@Address", c.Address);
                cmd.Parameters.AddWithValue("@Gender", c.Gender);

                conn.Open();
                int rows = cmd.ExecuteNonQuery();

                if (rows > 0)
                {
                    isSuccess = true;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error: " + ex.Message);
            }
            finally
            {
                conn.Close();
            }

            return(isSuccess);
        }