예제 #1
0
        //Inserting Data

        public bool Insert(supplierClass c)
        {
            bool isSuccess = false;

            SqlConnection conn = new SqlConnection(connectionString);

            try
            {
                //Sql query to insert data

                string sql = "INSERT INTO  supplierDetails(supplierNIC, firstName, lastName, contactNumber, supDate, email, companyName, gender) VALUES(@supplierNIC, @firstName, @lastName, @contactNumber, @supDate, @email, @companyName, @gender)";

                SqlCommand cmd = new SqlCommand(sql, conn);

                //parameters to add data

                cmd.Parameters.AddWithValue("@supplierNIC", c.supplierNIC);
                cmd.Parameters.AddWithValue("@firstName", c.firstName);
                cmd.Parameters.AddWithValue("@lastName", c.lastName);
                cmd.Parameters.AddWithValue("@contactNumber", c.contactNumber);
                cmd.Parameters.AddWithValue("@supDate", c.supDate);
                cmd.Parameters.AddWithValue("@email", c.email);
                cmd.Parameters.AddWithValue("@companyName", c.companyName);
                cmd.Parameters.AddWithValue("@gender", c.gender);

                //open dataBase connection
                conn.Open();

                //check rows greater than zero else will be 0
                int rows = cmd.ExecuteNonQuery();

                if (rows > 0)
                {
                    isSuccess = true;
                }

                else
                {
                    isSuccess = false;
                }
            }

            catch (Exception ex)
            {
            }

            finally
            {
                conn.Close();
            }

            return(isSuccess);
        }
예제 #2
0
        //Update data

        public bool Update(supplierClass c)
        {
            bool isSuccess = false;

            SqlConnection conn = new SqlConnection(connectionString);

            try
            {
                string sql = "UPDATE supplierDetails SET supplierNIC = '" + c.supplierNIC + "', firstName = '" + c.firstName + "', lastName = '" + c.lastName + "', contactNumber = '" + c.contactNumber + "', supDate = '" + c.supDate + "', email = '" + c.email + "', companyName = '" + c.companyName + "', gender = '" + c.gender + "' WHERE supplierID = '" + c.supplierID + "'";

                SqlCommand cmd = new SqlCommand(sql, conn);

                //cmd.Parameters.AddWithValue("@supplierNIC", c.supplierNIC);
                //cmd.Parameters.AddWithValue("@firstName", c.firstName);
                //cmd.Parameters.AddWithValue("@lastName", c.lastName);
                //cmd.Parameters.AddWithValue("@contactNumber", c.contactNumber);
                //cmd.Parameters.AddWithValue("@email", c.email);
                //cmd.Parameters.AddWithValue("@companyName", c.companyName);
                //cmd.Parameters.AddWithValue("@gender", c.gender);
                //cmd.Parameters.AddWithValue("@supplierID", c.supplierID);


                conn.Open();

                //check rows greater than zero else will be 0
                int rows = cmd.ExecuteNonQuery();

                if (rows > 0)
                {
                    isSuccess = true;
                }

                else
                {
                    isSuccess = false;
                }
            }

            catch (Exception ex)
            {
            }

            finally
            {
                conn.Close();
            }

            return(isSuccess);
        }
예제 #3
0
        //Delete data

        public bool Delete(supplierClass c)
        {
            bool isSuccess = false;

            SqlConnection conn = new SqlConnection(connectionString);

            try
            {
                //Delete data

                string sql = "DELETE FROM supplierDetails WHERE supplierID = @supplierID";


                SqlCommand cmd = new SqlCommand(sql, conn);
                cmd.Parameters.AddWithValue("@supplierID", c.supplierID);

                conn.Open();


                //check rows greater than zero else will be 0
                int rows = cmd.ExecuteNonQuery();

                if (rows > 0)
                {
                    isSuccess = true;
                }

                else
                {
                    isSuccess = false;
                }
            }

            catch (Exception ex)
            {
            }
            finally
            {
                conn.Close();
            }

            return(isSuccess);
        }